js how does sort work code example
Example 1: javascript sort array strings alphabetically
//sort array alphabetically
objArray.sort(function(a, b) {
return a.localeCompare(b);
});
Example 2: javascript order by string array
users.sort((a, b) => a.firstname.localeCompare(b.firstname))
Example 3: sort arrays according to first array js
itemsArray.sort(function(a, b){
return sortingArr.indexOf(a) - sortingArr.indexOf(b);
});