I have a third party function which returns an object
abc.xyz() --> this returns an object containing many objects,strings,boolean & arrays . Basically JSON style
object.
I am iterating through this object to get only the objects inside this object & that object should have a key named "apple" . Once I locate that object, I'm putting the key into a variable named "index" & then using that variable "index" to get the object that I want using
abc.xyz().index // This should ideally return an object, but this is undefined. Why?
My code below.
var pa= abc.xyz();
var index;
for(var key in pa){
if (pa.hasOwnProperty(key)) {
var obj = pa[key];
for(var prop in obj){
if(obj.hasOwnProperty(prop)){
if(typeof obj === 'object'){
if( prop == "apple"){
index = key;
}
}
}
}
}
}
el.appendChild(ul(pa.index)); // though I get the correct index when i
console.log(index) but why is pa.index undefined?
If I don't use index variable & I directly say pa.k where k is the value of index , it works. then why wont pa.index work?