Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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 ]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #sort #Array #descending #order
ADD COMMENT
Topic
Name
4+3 =