Returning Subset Of Properties From An Array Of Objects
I have an array of objects like var array = [{date:'01/01/2017',value1:200,value2:300,value3:400}] I am trying to get a subset of the object properties like var var newArray = [
Solution 1:
You should use map
for this, you were almost there. This will sort you out:
array.map(function(item){ return [item.date,item.value1]});
Solution 2:
You need to put the values in an array & map
method will do rest of the work
var array = [{
date: '01/01/2017',
value1: 200,
value2: 300,
value3: 400
}, {
date: '01/01/3017',
value1: 500,
value2: 300,
value3: 400
}];
var m = array.map(function(item) {
return [item.date, item.value1]
})
console.log(m)
[['01/01/2017',200],['01/01/2017',200]]
Post a Comment for "Returning Subset Of Properties From An Array Of Objects"