I'm trying to loop through items within an object and removing items with the property delete whose value is true to then post that object as data.
when I use splice to remove an item, I get an Uncaught TypeError: Cannot read property 'delete' of undefined error. Why is that?
https://jsfiddle.net/ah9td94q/3/
var data = {
"stuff":[
{"x":0},
{"y":1, "delete": true},
{"z":2, "delete": true}
]
}
Object.keys(data.stuff).forEach(function (key) {
if (data.stuff[key].delete == true) {
data.stuff.splice(key, 1);
}
});
var postData = JSON.stringify({something:'something', data: data});
console.log(postData);