Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

sort javascript number array with duplicates

//ascending order
console.log([1, 2, 0, 1].sort((a, b) => a - b))

//descending order
console.log([1, 2, 0, 1].sort((a, b) => b - a))
 Run code snippetHide results
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #sort #javascript #number #array #duplicates
ADD COMMENT
Topic
Name
7+5 =