// 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);
code
Sorting an Array
This JavaScript code demonstrates how to sort an array of numbers in ascending order using the Array.sort() method with a custom sorting function. The comments provide explanations for each part of the code.
Array
Sorting
Array.sort()
Arrow Function