arrays - Get javascript fields with specific names in object -
i have object such fields:
{ d_name: { field_name: true }, d_date: { field_date: isodate() }, status: 'success' } i need fields starting d_ , push them 1 array..
i need fields...
do mean need keys? if so:
var d_keys = object.keys(obj).filter(function (key) { return !key.indexof("d_"); }); if want values:
var d_values = object.keys(obj).filter(function (key) { return !key.indexof("d_"); }).map(function (key) { return obj[key]; }); note uses various es5 methods (object.keys, array.prototype.filter , array.prototype.map), depending on environment may need appropriate shims.
here working examples of both snippets.
Comments
Post a Comment