Sort array in ascending or descending order using sort function

Array :

let k=[1,3,11,2,33,22]

k.sort()

Result :
[1,11,2,22,3,33]

Here the array just sorted based on the ASCI values, so how to make it such way that it can return the array in ascending sort order.

k.sort((a,b)=>{return a-b})
use the fat arrow function
Result : [1,2,3,11,22,33]

descending sort order.
k.sort((a,b)=>{return b-a})

Result : [33,22,11,3,2,1]

Use the below tool to try ES6 javascript

https://stephengrider.github.io/JSPlaygrounds/


3 comments:

  1. Titanium Dentistry & Treatment - Home Page
    › help › titanium-dental-ac › 2018 ford fusion hybrid titanium help › titanium-dental-ac titanium exhaust tips Contact the support team at 3:00 titanium cookware am at Toll-Free-Casino. Visit our web site for details titanium water bottle and a quote. titanium hair straightener

    ReplyDelete
  2. Juggernaut: Sort Array In Ascending Or Descending Order Using Sort Function >>>>> Download Now

    >>>>> Download Full

    Juggernaut: Sort Array In Ascending Or Descending Order Using Sort Function >>>>> Download LINK

    >>>>> Download Now

    Juggernaut: Sort Array In Ascending Or Descending Order Using Sort Function >>>>> Download Full

    >>>>> Download LINK

    ReplyDelete