Answers for "sort a object of aaray in js"

11

javascript sort array of object by property

function sortByDate( a, b ) {
  if ( a.created_at < b.created_at ){
    return -1;
  }
  if ( a.created_at > b.created_at ){
    return 1;
  }
  return 0;
}

myDates.sort(sortByDate);//myDates is not sorted.
Posted by: Guest on February-11-2020
1

sort arrays according to first array js

itemsArray.sort(function(a, b){  
  return sortingArr.indexOf(a) - sortingArr.indexOf(b);
});
Posted by: Guest on August-17-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language