Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript sort array of objects ascending and descending order

// Price Low To High
array?.sort((a, b) => (a.price > b.price ? 1 : -1))
// Price High To Low
array?.sort((a, b) => (a.price > b.price ? -1 : 1))
// Name A to Z
array?.sort((a, b) => (a.name > b.name ? 1 : 1))
// Name Z to A
array?.sort((a, b) => (a.name > b.name ? -1 : 1))
// Sort by date
array.sort((a,b) =>  new Date(b.date) - new Date(a.date));
Comment

descending order in objects in js

starWarsPeople.map(e=>{
    return e
  }).sort((a,b)=> b.height - a.height);
Comment

javascript sort object by value descending

javascript sort object by value descending


starWarsPeople.map(e=>{
    return e
  }).sort((a,b)=>{
    if (a.height-b.height>1) {return -1;}
    else if (a.height-b.height<1) {return 1;}
    else {return 0;}
  });
Comment

PREVIOUS NEXT
Code Example
Javascript :: react native red triangle up 
Javascript :: datatables server side 
Javascript :: how to set empty date in javascript 
Javascript :: javascript get call stack 
Javascript :: print element by xpath javascript 
Javascript :: javascript regex Zero or one occurrence 
Javascript :: js array from 
Javascript :: reactjs dynamic route 
Javascript :: how to get the inner width of a parent div for canvas 
Javascript :: javascript compare two arrays of objects 
Javascript :: how to remove quotes using regex 
Javascript :: replace jquery 
Javascript :: react promises 
Javascript :: move first element to last javascript 
Javascript :: fetch get request 
Javascript :: parse string to int nodejs 
Javascript :: get position of element in react 
Javascript :: turnery opertaor js 
Javascript :: react native vector icons not working 
Javascript :: upload excel file using jquery ajax 
Javascript :: clear element children js 
Javascript :: concatenate multiple arrays javascript 
Javascript :: how to iterate array in javascript 
Javascript :: copy text on button click in jquery 
Javascript :: javascript default parameters 
Javascript :: javascript debouncing 
Javascript :: Uncaught (in promise) ReferenceError: React is not defined 
Javascript :: javascript show page 
Javascript :: passport local mongoose 
Javascript :: array.from foreach 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =