Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript sort Array descending order

//used arraow functions
const years = [1970, 1999, 1951, 1982, 1963, 2011, 2018, 1922]
const sortYears = arr =>{
  arr.sort((a,b)=>{return b-a})
  return arr
}
console.log(sortYears(years))
// Should print [ 2018, 2011, 1999, 1982, 1970, 1963, 1951, 1922 ]
Comment

sort array descending

testsSortedByNome = tests.sort((a, b) => (a.nome > b.nome ? -1 : 1));
testsSortedByCognome = tests.sort((a, b) => (a.cognome > b.cognome ? -1 : 1));
Comment

array sorting descending

employees.sort((a, b) => b.age - a.age);

employees.forEach((e) => {
    console.log(`${e.firstName} ${e.lastName} ${e.age}`);
});
Code language: JavaScript (javascript)
Comment

PREVIOUS NEXT
Code Example
Javascript :: Forward propagation in NN 
Javascript :: update reducer 
Javascript :: three js html 
Javascript :: jquery with svelte 
Javascript :: create random password 
Javascript :: javascript open method 
Javascript :: object destructuring es6 
Javascript :: next js latest 
Javascript :: button click 
Javascript :: progressbar javascript 
Javascript :: javascript even number 
Javascript :: vuejs events modifier 
Javascript :: function as object 
Javascript :: javascript compare dates 
Javascript :: history.pushstate 
Javascript :: jquery accordion toggle close open 
Javascript :: frames[i] js 
Javascript :: jq not contains 
Javascript :: all jquery selectors 
Javascript :: async.each javascript 
Javascript :: get vue-emoji-picker 
Javascript :: asynchronous javascript 
Javascript :: javascript append array to end of array 
Javascript :: js get variable from url 
Javascript :: break out of map javascript 
Javascript :: js array join 
Javascript :: react native time range picker 
Javascript :: Agora Video Calls 
Javascript :: template literals in js 
Javascript :: react.dom 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =