8 Replies
so imagine i created an array
The explanation on MDN is better than I can do: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
mozillaðŸ˜
actually my concern is with whats being printed in the console option
i will retake the screenshot
here is the code and the console page
i wanna know why when i declared the value of array[12] and array [29]
and used the sort() function
then in the console, it shifted the value to array[0] and array [1] rather than array[12] and array[29]
because it's been sorted
From the MDN article:
If compareFn is not supplied, all non-undefined array elements are sorted by converting them to strings and comparing strings in UTF-16 code units order. For example, "banana" comes before "cherry". In a numeric sort, 9 comes before 80, but because numbers are converted to strings, "80" comes before "9" in the Unicode order. All undefined elements are sorted to the end of the array.
oh
now i got it
thanks😀
np 🙂