I have this array containing simple objects
var data = [
{type:1, owner:"jason"},
{type:1, owner:"john"},
{type:2, owner:"jason"},
{type:2, owner:"alice"},
{type:2, owner:"bob"},
{type:2, owner:"clark"},
{type:1, owner:"david"}
]
i am trying to loop through the array and removing only elements with type:1. This is what i tried.
for(var i = 0; i < data.length; i++){
if(data[i].type === 1){
data.splice(i,1)
}
}
Would it be stupid of me to assume that after that loop runs that all type 1 elements will be removed from the array. After running this in chrome dev tools, the array still contains {type:1, owner:"jason"} and all type:2's were left untouched as expected. what am i doing wrong?