Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript sort a b

//This method will be sort array in ascending order:
var numArray = [5, 10, 12, 9, 31, 21, 18, 55, 39, 40];
numArray.sort((a, b) => {
  return a - b;
});
console.log(numArray);

//This method will be sort array in descending order:
numArray.sort((a, b) => {
  return b - a;
});

console.log(numArray)

//sort array by date

// Name Z to A
array.sort((a, b) => (a.name > b.name ? -1 : 1))

console.log(array)
// Sort by date
array.sort((a,b) =>  new Date(a.date) - new Date(b.date));

console.log(array)
Comment

PREVIOUS NEXT
Code Example
Javascript :: react native prevent rotation of screen 
Javascript :: arrow functions in es6 
Javascript :: convert json into map in java example 
Javascript :: js push array into array 
Javascript :: Javascript screenshot in video 
Javascript :: current date in mongodb 
Javascript :: react key press hook 
Javascript :: class constructor javascript 
Javascript :: reset select2 jquery | clear select2 option value 
Javascript :: save networkx graph to json 
Javascript :: gsheet query select remove header 
Javascript :: zustand simple counter 
Javascript :: how to check if something is array javascript 
Javascript :: node js url download 
Javascript :: bcrypt 
Javascript :: express session 
Javascript :: how to convert an array into single quote strings 
Javascript :: js add to map 
Javascript :: radio button checked jquery 
Javascript :: how to update node in terminal 
Javascript :: add next to react 
Javascript :: background image not loading from a link react 
Javascript :: document.getelementbyid 
Javascript :: split string to char js 
Javascript :: uppercase-the-first-letter-of-a-string-using-javascript/ 
Javascript :: javascript get current window location without parameters 
Javascript :: javascript countdown 
Javascript :: javascript fill 2 dimensional array 
Javascript :: Nestjs download 
Javascript :: is knex built into node js 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =