I have starting data with 2 entries:
var startdata = [{id: 1454498069524, lender: "examplelender", deptor: 'exampledeptor', amount: 10, text: "exampletext"}, {id: 1454498069511, lender: "examplelender2", deptor: 'exampledeptor2', amount: 102, text: "exampletext2"} ];
and I save this data in React State
.
Then I try to delete from this State
with a key value, but can't figure out how.
I tried:
handleDeptDelete: function(deptID) {
var depts = this.state.data;
var newDepts = depts;
// delete newDepts[1454498069524]; // doesn't delete
// delete {id: depts.deptID}; // doesn't delete
newDepts.splice({id: deptID}, 1); // deletes always the first entry no matter of the ID
this.setState({data: newDepts});
},
I have console logs to show that the ID is correct and with the most recent try (the one not commented) I manage to delete something (always the first one in the data), so the update is working also fine.
How do I delete the second one? Making this:
{id: 1454498069524, lender: "examplelender", deptor: 'exampledeptor', amount: 10, text: "exampletext"}, {id: 1454498069511, lender: "examplelender2", deptor: 'exampledeptor2', amount: 102, text: "exampletext2"}
Into this:
{id: 1454498069524, lender: "examplelender", deptor: 'exampledeptor', amount: 10, text: "exampletext"}
I am able to get all the data of the entry, not just ID, but I thought it should be enough.
I don't have the data on server so I can't use This SO solution. Other ones I looked through are this and this with no help.