(function(){
var arrayNumb = [2, 8, 15, 16, 23, 42];
arrayNumb.sort();
console.log(arrayNumb);
})();
Why does this print [ 15, 16, 2, 23, 42, 8 ]?
(function(){
var arrayNumb = [2, 8, 15, 16, 23, 42];
arrayNumb.sort();
console.log(arrayNumb);
})();
Why does this print [ 15, 16, 2, 23, 42, 8 ]?
The default sort order is built upon converting the elements into strings, then comparing their sequences of UTF-16 code units values.
If you want to order them differently than that you need a callback function