I am having trouble deleting JSON elements that meet a certain condition. I tried using the following code:
var index = -1;
for (var i = 0; i < data.dashLayout.dashlets.length; i++) {
if (data.dashLayout.dashlets[i].rowNo == selectedrowno) {
if (index == -1 || data.dashLayout.dashlets[i].rowNo < data.dashLayout.dashlets[index].rowNo) {
index = i;
}
}
if (index != -1) {
data.dashLayout.dashlets.splice(index, 1);
}
}
The issue I'm facing is that the iteration is not completing because the data.dashLayout.dashlets.length
keeps decreasing with each splice operation. Can someone please help me solve this problem? I need to delete all items that satisfy the condition.