Lets say i have this object and the first two have the property bought(how many of them the user bought)
var Drugs = {
Extasy : {
name : "Extasy",
value: 0,
bought : 2,
hist : [],
qty : 0
},
Hash : {
name : "Hash",
value: 0,
hist : [],
bought: 3,
qty : 0
},
Adrenaline : {
name : "Adrenaline",
value: 0,
hist : [],
qty : 0
},
Cocaine : {
name : "Cocaine",
value: 0,
hist : [],
qty : 0
},
Mdma : {
name : "Mdma",
value: 0,
hist : [],
qty : 0
}
};
and i want to loop through the Drugs object in order to find out which of them has the bought property.
var outputs = '<li class="ui-li-has-count">';
for (var d in Drugs) {
var dd = Drugs[d];
if (Drugs.hasOwnProperty(dd.bought)) {
// if (dd.bought != 'undefined' ){
outputs+='<a class="ui-btn ui-btn-icon-right ui-icon-carat-r" href="#myPopup" onclick="buyPopup(this.id)" id='+dd.name+' >'+dd.name+'<span class="ui-li-count">'+dd.bought+'</span> ';
}
else {
outputs = false;
}
outputs += '</li></div>';
}
//getElementById
ast("panel1").innerHTML += outputs;
Even if my bought key has a property i always get false
hasOwnPropertyis a method that only requires the name. So changedd.boughtto just'bought'