javascript - Whitelist a set of properties from a multidimensional json array and delete the rest -
for examples sake i'll use github api response data input.
https://api.github.com/users/unsalted/repos
i have list of properties want keep, rest want discard because want keep output i'm generating considerably more compact.
how can achieve goal without doing this:
(var = tagged.length - 1; >= 0; i--) { delete tagged[i].private; delete tagged[i].owner.gravatar_id; delete tagged[i].owner.url; delete tagged[i].owner.followers_url; delete tagged[i].owners.following_url; delete tagged[i].gravatar_id; delete tagged[i].private; delete tagged[i].private; delete tagged[i].private; delete tagged[i].private; delete tagged[i].private; delete tagged[i].private; delete tagged[i].private; delete tagged[i].private; delete tagged[i].private; delete tagged[i].private; delete tagged[i].private; delete tagged[i].private; delete tagged[i].private; delete tagged[i].private; delete tagged[i].private; delete tagged[i].private; delete tagged[i].private; delete tagged[i].private; };
i using lodash in project lodash solutions more welcome.
for times sake didn't fill out rest of values idea...
for given object, can use _.pick
keep properties specify; , can map on collection. so, end with:
tagged = _.map(tagged, function (t) { return _.pick(t, ['properties', 'to', 'keep']); });