Isaac
asked on
Retrieve index value from JSON
How can I retrieve the index of a JSON array? In my json, there's a PlanNumber with a value and I need to retrieve the index. The Json in my fiddle show 5 contracts and each having a plan number.
Not working for me.
Not working for me.
var index = -1;
var val = "8930-3o3pp";
var filteredObj = jsonFile.Result.Contracts.find(function(item, i){
if(item.Plan.PlanNumber === val){
index = i;
return i;
}
});
alert(index, filteredObj);
https://jsfiddle.net/isogunro/z6f33doy/3/
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
When I move it to my site, I get "object doesn't support property or method .find"
ASKER
That sucks, IE does not support .find()
ASKER
I will try the polyfil. hopefully it works
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
ASKER
I see what I did wrong.