Learn, grow and help others with BBBootstrap
Contribute us with some awesome cool snippets using HTML,CSS,JAVASCRIPT and BOOTSTRAP
Sorting with long numbers in Javascript ES6. If the numbers are bigger than 9 - we can use regular expressions to find them and sort elements of the array based on their values.
const r = /\d+/; const alphanumbers = ['items 12','items 11','items 1302','items 999','items 144']; const sortnumbers = alphanumbers.sort((a,b) => { return a.match(r) - b.match(r); }); console.log(sortnumbers); // ['items 11', 'items 12', 'items 144', 'items 999', 'items 1302']