javascript sort integers code example
Example 1: javascript sort array smallest to largest
var numArray = [140000, 104, 99];
numArray.sort(function(a, b) {
return a - b;
});
console.log(numArray);
Example 2: javascript sort numbers
var numArray = [140000, 104, 99];
numArray.sort(function(a, b) {
return a - b;
});
Example 3: sort numbers in array javascript
function sortNumber(a, b) {
return a - b;
}
Arr.sort(sortNumber);
Example 4: how to sort array least to greatest javascript stACK
function sortArray(array) {
var temp = 0;
for (var i = 0; i < array.length; i++) {
for (var j = i; j < array.length; j++) {
if (array[j] < array[i]) {
temp = array[j];
array[j] = array[i];
array[i] = temp;
}
}
}
return array;
}
console.log(sortArray([3,1,2]));