Q:

alphabetical order array javascript

users.sort((a, b) => a.firstname.localeCompare(b.firstname))
2
var numbers = [4, 2, 5, 1, 3];
numbers.sort(function(a, b) {
  return a - b;
});
console.log(numbers);

// [1, 2, 3, 4, 5]
3

        
            
        
     let numbers = [0, 1, 2, 3, 10, 20, 30];
numbers.sort((a, b) => a - b);

console.log(numbers);
0
//sorts arrays of numbers
function myFunction() {
  points.sort(function(a, b){return a-b});
  document.getElementById("demo").innerHTML = points;
}
2
arr.sort(function(a, b) {
    return a === b ? 0 : a < b ? -1 : 1;
  });
0

New to Communities?

Join the community