I have built an array-object structure as below
nestedArray = [ { source : "a" , target : "b", table : "ab" },
{ source : "c" , target : "d", table : "cd" },
{ source : "a" , target : "d", table : "cd" },
{ source : "a" , target : "f", table : "cd" }];
And I wrote below code to remove all nested objects where source
is a
.
nestedArray.forEach(function(element) {
if(element.source == "a") {
nestedArray.splice(nestedArray.indexOf(element), 1) ;
}
});
But when I try printing the array after above code, I can still see an object with source
as a
.
> > nestedArray
[ { source: 'c', target: 'd', table: 'cd' },
{ source: 'a', target: 'f', table: 'cd' } ]
> >
Am I missing anything here ? Any suggestions greatly appreciated.