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
Post a Comment