Learn, grow and help others with BBBootstrap
Contribute us with some awesome cool snippets using HTML,CSS,JAVASCRIPT and BOOTSTRAP
Sorting numbers in arrays in Javascript ES6. If we want to use the javascript sort
method with numerical values, we need to pass it inside a callback arrow function, which will handle the comparison of values.
const numbers = [1,5,3,2,19,8,4,18]; const sortnumbers = numbers.sort((a,b)=>a-b); console.log(sortnumbers); // [1, 2, 3, 4, 5, 8, 18, 19]