Consider this snippet.
console.log([10, 2, 5].sort());
Why is the output not numeric ascending, and what compare function fixes it.
Hari
Consider this snippet.
console.log([10, 2, 5].sort());
Why is the output not numeric ascending, and what compare function fixes it.
Hari
sort() compares as strings by default, so "10" comes before "2".
Ellen
:: Copyright KIRUPA 2024 //--