Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other Var Shuffle array…I need to have my array NOT shuffle..help! Reply To: Var Shuffle array…I need to have my array NOT shuffle..help!

#241780
Jerba
Participant

You can use the native Array.sort function to order array values.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort

var numbers = [1, 9, 3, 6, 7, 11, 45, 194];

var ASC = numbers.sort(function(previous, current) {
  return previous - current;
});

var DESC = numbers.sort(function(previous, current) {
  return current - previous;
});