javascript - Manipulating JSON data sets -


so have array myarr[] of json objects in form: { "a":"", "b":"" }

are there efficient methods getting array of b:

[ myarr[0].b, myarr[1].b, myarr[2].b, ... ]

or have manually iterate through myarr build array of b?

why not have fun prototypes , extend array obtain handy , reusable function:

array.prototype.pluck = function(key) {     var = this.length,          plucked = [];     while(i --) {         plucked[i] = this[i][key] || ""     }      return plucked; } 

with one, can do:

collection.pluck(keyname) 

to desired result. check here working demo: http://jsfiddle.net/jyrnn/1/


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -