I have an object and I want to remove the element from it.
Eg : My object is like as below
var DecisionObj = '{"Decision":[{"recid":"1183","reason":"Approved but with different Funding Amount","decision":"Approved","approvalamt":"","comment":""},{"recid":"662","reason":"Approved but with different Funding Amount","decision":"Approved","approvalamt":"","comment":""},{"recid":"752","reason":"Approved but with different Funding Amount","decision":"Approved","approvalamt":"","comment":""}]}';
Suppose I want to delete row with recid = 662
Below is the code i tried
var DecisionObj = '{"Decision":[{"recid":"1183","reason":"Approved but with different Funding Amount","decision":"Approved","approvalamt":"","comment":""},{"recid":"662","reason":"Approved but with different Funding Amount","decision":"Approved","approvalamt":"","comment":""},{"recid":"752","reason":"Approved but with different Funding Amount","decision":"Approved","approvalamt":"","comment":""}]}';
obj = JSON.parse(DecisionObj);
console.log("BEFORE==="+JSON.stringify(obj));
var ddcnt = obj.Decision.length;
var recval = 662;
for (e = 0; e < ddcnt; e++)
{
//var DRecVal = obj.Decision[e].recid;
var DRecVal = obj.Decision[e].recid;
if(recval == DRecVal)
{
obj.Decision.splice(e,1);
}
}
console.log("AFTER==="+JSON.stringify(obj));
But the above code gives me an error like TypeError: obj.Decision[e] is undefined on line 21.
How shall I solve this.Help appreciated!Thanks!
for(properties in obj.Decision)and accessDRecValbyproperties.recid