Created
March 13, 2021 08:46
-
-
Save 911992/4a03c0e28b97bd0f2ff1197ab0e4f33d to your computer and use it in GitHub Desktop.
JS array ascending sort sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arr = [1,9,4,1,00,5,333,222]; | |
arr.sort(function(a,b){ | |
var _a=Number(a); | |
var _b=Number(b); | |
return _a - _b; | |
}); | |
console.log(arr); | |
/* | |
out: | |
[0, 1, 1, 4, 5, 9, 222, 333] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also
[0, 0.731, 0.123, 0.237, 0.397, 0.411, 0.5123, 0.9777]