Problem
I'm pushing values from my JavaScript functions and filling an array with objects. what I would like to happen is remove key + Value pairs that are zero.
example of return array
[Object percent: 516 unit: -10.689124404913258
Object percent: 516 unit: -9.011227255423254
Object percent: 561 unit: -12.669770888525518
Object percent: 6516 unit: -15.99180968320506
Object percent: 0 unit: 0]
JavaScript
my_arr = []
for(var i = my_arr.length - 1; i >= 0; i--) {
if(array[i] === 0) {
array.splice(i, 1);
}
return my_arr;
}
array[i] === 0toarray[i]['percent'] === 0 || array[i]['unit'] === 0. Change the || to && if both properties should be 0 for the object to be removed.