Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript sort array by Z-A in js

// 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

PREVIOUS NEXT
Code Example
Javascript :: javascript sort in array of objects 
Javascript :: javascript random boolean 
Javascript :: jquery get src of image 
Javascript :: how to enable and disable href in javascript 
Javascript :: how to set form control value in angular 
Javascript :: javascript date set weeks 
Javascript :: js split text on spaces 
Javascript :: get select option count using jquery 
Javascript :: how to check if object is undefined in javascript 
Javascript :: javascript replace multiple spaces with single space 
Javascript :: how to hack the chrome dinosaur game 
Javascript :: javascript pad with leading zeros 
Javascript :: get number of days in a month javascript 
Javascript :: Datatable Change page size for pdf 
Javascript :: check textbox is empty in jquery 
Javascript :: javascript clear text in textarea 
Javascript :: jquery check input 
Javascript :: error: bundling failed: Error: Unable to resolve module react-native-community/toolbar-android 
Javascript :: dont drag img 
Javascript :: reactjs variable in string 
Javascript :: capitalize first letter javascript 
Javascript :: javascript max safe integer 
Javascript :: electron specify minimum size 
Javascript :: how to find out if mongoose is connected or not 
Javascript :: insta icon in next js 
Javascript :: window.history.pushstate typescript 
Javascript :: js create date from string 
Javascript :: nuxt 18 mountend route push 
Javascript :: get x characters from string javascript 
Javascript :: local storage check max size 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =