I have an obj, with an array of objects - something like below (I've not pasted it here because its HUGE). I'm trying to loop through the array of objects - deleting those objects from the array which contain a value. I have written the following code... (using lodash)
When looping over the array its randomly missing a few 'Foo's - so not all the Foo objects are deleted... even though they contain the key Foo. It does ignore that which doesn't contain Foo though.
obj = {
array : [
{
key1 : 'Foo',
Key2 : 'fi'
},
{
key1 : 'Foo',
Key2 : 'fi',
Key3 : 'blah'
},
{
key1 : 'Fred',
Key2 : 'fi'
},
{
key1 : 'Foo',
Key2 : 'fi'
}
... etc....
]
}
var items = obj.array
_.forEach(items, function(n, index) {
var isFoo = _.includes(n, 'Foo');
console.log(isFoo);
if (isFoo) {
items.splice(index, 1);
}
});