sort() : It is used to arrange elements of an array. It modifies the original array. By default, the sort() method converts all elements into strings and sorts them in ascending order based on their Unicode values. Works perfectly for strings. For numbers, the default comparator converts elements to strings, which causes unexpected results with numbers. So we must provide a compare function as an argument. The function compares two elements (a and b) and returns a value. Negative value: a is pla
Comment
Sign in to join the discussion.
Loading comments…