DeveloperBreeze

Sorting an Array

// Array of numbers
const numbers = [4, 2, 8, 1, 6];

// Sorting the array in ascending order
const sortedNumbers = numbers.sort((a, b) => a - b);

// Logging the sorted array
console.log('Sorted Array:', sortedNumbers);

Related Posts

More content you might like

Code
javascript

Sorting an Array in JavaScript

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

Image Slider

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

JavaScript Sum of Array Elements

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

JavaScript Remove Duplicates from an Array

No preview available for this content.

Jan 26, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Be the first to share your thoughts!