I have a variable called today
that stores data retrieved from an API. I'm attempting to delete some information from it using a function, but I keep encountering the error message
Cannot read property 'id' of undefined.
SAMPLE DATA
[
{
"id":324,
"firstName":"Chris",
"lastName":"Jake",
"orders":[
{
"id":162,
"meals":[
{
"id":27,
"name":"French Fries",
"description":"test"
},
{
"id":28,
"name":"Plain Rice, Beans and Fish",
"description":"test"
}
],
"serveDate":"2019-07-16 00:00:00"
}
]
}
]
DELETE FUNCTION
delete() {
for (let r = 0; r < this.today.length; r++) {
if (this.today[r].orders[r].id === this.orderId) {
this.today.splice(r, 1);
}
}
}