I have a data structure like this:
var data = [
[
[0,0,4],
[0,1,4],
[0,0,4],
[0,0,4]
],
[
[0,1,4],
[0,1,4],
[0,0,4],
[0,1,4]
],
[
[0,0,4],
[0,0,4],
[0,1,4],
[0,1,4]
]
];
Specifically, I'm interested in whether the value of the second item in each inner-most array is 0
or not. If that value is zero, I want to remove the entire array that harbors that value.
Based on the conventional approach for removing things from arrays seen here: How can I remove a specific item from an array? I attempted the following:
for (var j = 0; j < 3; j++) {
for (var k = 0; k < 4; k++) {
var thisArray = data[j][k];
if (thisArray[1] == 0) {
data[j].splice(k, 1);
}
}
}
However, this seemed to remove my whole data, as nothing even appeared in my console log -- not even undefined.
Question
How does one remove an entire array based on a condition?