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 array of objects by number 
Javascript :: how to get random boolean in javascript 
Javascript :: xss test 
Javascript :: apply back button to a react component 
Javascript :: how to run angular 
Javascript :: node js on ctrl c 
Javascript :: how to check if enter is pressed javascript 
Javascript :: js get first element by class 
Javascript :: javascript change color for class name 
Javascript :: javascript replace two spaces with one 
Javascript :: get position of element 
Javascript :: javascript pad number with leading zeros 
Javascript :: react hide source code 
Javascript :: Bootstrap modal hide and show 
Javascript :: how to convert string to int a array in javascript 
Javascript :: jquery uncheck checkbox 
Javascript :: javascript typeof undfined 
Javascript :: append option to select ajax javascript 
Javascript :: discord.js create unexipable invite 
Javascript :: how to check if a json object contains a key in jquery 
Javascript :: mui usetheme 
Javascript :: increment day date javascript 
Javascript :: js get user location 
Javascript :: nextjs create project with tailwind 
Javascript :: fontawesome in next js 
Javascript :: Codewars Calculate average 
Javascript :: change placeholder text jquery 
Javascript :: js mobile prevent image mousedown 
Javascript :: Get current active sheet name google appscript 
Javascript :: javascript custom events with data 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =