sorting - Javascript: sort multidimensional array -


after creating multi-dim array this, how sort it?

assuming 'markers' defined:

var location = []; (var = 0; < markers.length; i++) {   location[i] = {};   location[i]["distance"] = "5";   location[i]["name"] = "foo";   location[i]["detail"] = "something"; } 

for above example, need sort 'distance'. i've seen other questions on sorting arrays , multi-dim arrays, none seem work this.

location.sort(function(a,b) {    // assuming distance valid integer   return parseint(a.distance,10) - parseint(b.distance,10);  }); 

javascript's array.sort method has optional parameter, function reference custom compare. return values >0 meaning b first, 0 meaning a , b equal, , <0 meaning a first.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -