Answers for "ordering array javascript"

7

javascript sort

homes.sort(function(a, b) {
    return parseFloat(a.price) - parseFloat(b.price);
});
Posted by: Guest on March-17-2020
0

how to sort an array in javascript

const points = [40, 100, 1, 5, 25, 10];
points.sort(function(a, b){return a - b}); // for ascending
//another way for ascending
points.sort((a,b)=>{
  if(a>b){
      return 1
  }else if(a<b){
      return -1
  }else{
      return 0
  }
})
points.sort(function(a, b){return b - a}); // for descending
//another way for descending
points.sort((a,b)=>{
  if(a>b){
      return -1
  }else if(a<b){
      return 1
  }else{
      return 0
  }
})
Posted by: Guest on August-23-2021
4

javascript sort

homes.sort((a, b) => parseFloat(a.price) - parseFloat(b.price));
Posted by: Guest on March-17-2020

Browse Popular Code Answers by Language