I have my original objects as follow. All I need is to just extract few properties from existing one and create new object.
var data = [{
id: 3,
name: Axe,
location: alkt
}, {
id: 5,
name: Roy,
location: grelad
}]
I need my output as,
var data_new = [{
id: 3,
name: Axe
}, {
id: 5,
name: Roy,
}]
How to implement in underscore js or any simple method. Possible its a large JSON object.
It you want remove each item's location
If all you want is remove properties from objects in an array, you could just
delete
them while iterating withforEach
:Use pick in undescorejs http://underscorejs.org/#pick Or omit http://underscorejs.org/#omit
If there are just few properties you want to extract then simple Array.prototype.map will works fine: