Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to sort an array in js

//ascending order
let ArrayOne = [1,32,5341,10,32,10,90]
ArrayOne = ArrayOne.sort(function(x,y){x-y})
//descending order
let ArrayTwo = [321,51,51,324,111,1000]
ArrayTwo = ArrayTwo.sort(function(x,y){y-x})
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #sort #array #js
ADD COMMENT
Topic
Name
5+9 =