I would like to remove the key + value of objects which have value of 0. the timestamp should stay in place.
var array = [{
"timestamp": "2017-01-18T00:00:00.000Z",
"Test Bar 0": 78.09482851766388
}, {
"timestamp": "2017-01-18T01:00:00.000Z",
"Test Bar 0": 124.09589189108233
}, {
"timestamp": "2017-01-18T02:00:00.000Z",
"Test Bar 0": 106.97921714748477
}, {
"timestamp": "2017-01-18T03:00:00.000Z",
"Test Bar 0": 118.7469310337081
}, {
"timestamp": "2017-01-18T04:00:00.000Z",
"Test Bar 0": 119.81672320518294
}, {
"timestamp": "2017-01-18T05:00:00.000Z",
"Test Bar 0": 67.39690680291541
}, {
"timestamp": "2017-01-18T06:00:00.000Z",
"Test Bar 0": 117.67713886223325
}, {
"timestamp": "2017-01-18T07:00:00.000Z",
"Test Bar 0": 87.72295806093751
}, {
"timestamp": "2017-01-18T08:00:00.000Z",
"Test Bar 0": 115.53755451928356
}, {
"timestamp": "2017-01-18T09:00:00.000Z",
"Test Bar 0": 78.09482851766388
}, {
"timestamp": "2017-01-18T10:00:00.000Z",
"Test Bar 0": 48.14064771636815
}, {
"timestamp": "2017-01-18T11:00:00.000Z",
"Test Bar 0": 67.39690680291541
}, {
"timestamp": "2017-01-18T12:00:00.000Z",
"Test Bar 0": 130.5146449199314
}, {
"timestamp": "2017-01-18T13:00:00.000Z",
"Test Bar 0": 128.37506057698172
}, {
"timestamp": "2017-01-18T14:00:00.000Z",
"Test Bar 0": 73.81565983176449
}, {
"timestamp": "2017-01-18T15:00:00.000Z",
"Test Bar 0": 109.11880149043446
}, {
"timestamp": "2017-01-18T16:00:00.000Z",
"Test Bar 0": 127.30526840550688
}, {
"timestamp": "2017-01-18T17:00:00.000Z",
"Test Bar 0": 123.02609971960749
}, {
"timestamp": "2017-01-18T18:00:00.000Z",
"Test Bar 0": 0
}, {
"timestamp": "2017-01-18T19:00:00.000Z",
"Test Bar 0": 0
}, {
"timestamp": "2017-01-18T20:00:00.000Z",
"Test Bar 0": 0
}, {
"timestamp": "2017-01-18T21:00:00.000Z",
"Test Bar 0": 0
}, {
"timestamp": "2017-01-18T22:00:00.000Z",
"Test Bar 0": 0
}, {
"timestamp": "2017-01-18T23:00:00.000Z",
"Test Bar 0": 0
}, {
"timestamp": "2017-01-19T00:00:00.000Z",
"Test Bar 0": 0
}, {
"timestamp": "2017-01-19T01:00:00.000Z",
"Test Bar 0": 0
}, {
"timestamp": "2017-01-19T02:00:00.000Z",
"Test Bar 0": 0
}, {
"timestamp": "2017-01-19T03:00:00.000Z",
"Test Bar 0": 0
}, {
"timestamp": "2017-01-19T04:00:00.000Z",
"Test Bar 0": 0
}, {
"timestamp": "2017-01-19T05:00:00.000Z",
"Test Bar 0": 0
}, {
"timestamp": "2017-01-19T06:00:00.000Z",
"Test Bar 0": 0
}, {
"timestamp": "2017-01-19T07:00:00.000Z",
"Test Bar 0": 0
}, {
"timestamp": "2017-01-19T08:00:00.000Z",
"Test Bar 0": 0
}, {
"timestamp": "2017-01-19T09:00:00.000Z",
"Test Bar 0": 0
}, {
"timestamp": "2017-01-19T10:00:00.000Z",
"Test Bar 0": 0
}, {
"timestamp": "2017-01-19T11:00:00.000Z",
"Test Bar 0": 0
}]
var abc = array.filter((object) => {
let keys = []
for (let key in object) {
if (key !== 'timestamp') keys.push(key)
}
return keys.map(key => object[key] > 0)
})
console.log(abc)
However my code doesn't remove 0 values
filterfunction?timestampand returned only> 0mapdoesn't filter. You're just creating a list of boolean values with that map by the looks of it. I think you meantfilter.