Friday, 7 April 2017

Sorting array of numbers

I have some certain things which will be pushed into array like that (down below) and I would like to sort the item(s) by the item price. I tried using a sort but it doesn't work for me. After that I would like to loop that array and retrieve the item name and a item price.

Pushing item into array: array.push(itemName,itemPrice)

Trying to use sort function:

array.sort(function(a,b){
    return b[1] - a[1]
});



via Lew

No comments:

Post a Comment