Skip to content

Instantly share code, notes, and snippets.

@911992
Created March 13, 2021 08:46
Show Gist options
  • Save 911992/4a03c0e28b97bd0f2ff1197ab0e4f33d to your computer and use it in GitHub Desktop.
Save 911992/4a03c0e28b97bd0f2ff1197ab0e4f33d to your computer and use it in GitHub Desktop.
JS array ascending sort sample
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]
*/
@911992
Copy link
Author

911992 commented Mar 13, 2021

Also [0, 0.731, 0.123, 0.237, 0.397, 0.411, 0.5123, 0.9777]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment