0
What is the role of Array.sort() in JS?
What is the role of Array.sort() in JS?
// Functionless
sort()
// Arrow function
sort((firstEl, secondEl) => { ... } )
// Compare function
sort(compareFn)
// Inline compare function
sort(function compareFn(firstEl, secondEl) { ... })
const fruits = ['BANANA','APLLE','orang','grapes','mango'];
fruits.sort();
console.log(fruits);
// expected output: Array ['Dec', 'Feb', 'Jan', 'March']
const array1 = [54,21,32,5,1,21];
const array= array1.sort(function(a,b){
return a-b;
});
console.log(array);