Jquery array filtering - grep()? -


how can sort array 1 shown below jquery's own functions? assume grep() 1 should looking at?

thanks!

the array:

array (      array(         'id' => 0,         'name' => 'myname',         'weight' => 100       );      array(         'id' => 1,         'name' => 'myname2',         'weight' => 150,     );  ); 

edit: it's php array clarify things - im not sure how write proper javascript (json?) array?

first, i'm going assume you're talking javascript array looks this:

var myarray = [     {         id: 0,         name: 'myname',         weight: 100     },     {         id: 1,         name: 'myname2',         weight: 150     } ] 

you can call native javascript function sort() on array. in case, you'll need provide function callback. needs defined syntax function (a, b). a , b elements in array. need return -1 if a should higher ranked b in array, 1 if should lower ranked , 0 if equal.

if want sort them in descending order of weight, following:

myarray.sort(function(a, b) {     return b.weight - a.weight; }); 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -