I'm trying to loop over some data that look like this:
[0]['fields']['status']['name'] = 'In progress'
[1]['fields']['status']['name'] = 'In progress'
[2]['fields']['status']['name'] = 'In review'
[3]['fields']['status']['name'] = 'In progress'
[4]['fields']['status']['name'] = 'In review'
I'm using the following foreach loop to splice all useless indexes, in this case all of them.
issues.forEach(function (item, index) {
if (issues[index]['fields']['status']['name'] !== "Done") {
issues.splice(index, 1);
}
});
If I loop over the array later I can output 'In progress' and 'In review' which is weird because they should be unset. I think this happens because I manipulate the array while using it. Could someone explain what's wrong and how this can be avoided.
["a", "b", "c", "d"]and spliceindex = 0you get rid of"a"and you're left with["b", "c", "d"]. Next time the callback will be called withindex = 1so you remove the wrong item.