var validCoins = {
"nickel": {
"weight": 5.00,
"diameter": 21.21,
"thickness": 1.95,
"value": 0.05
},
"dime": {
"weight": 2.27,
"diameter": 17.91,
"thickness": 1.35,
"value": 0.10
},
"quarter": {
"weight": 5.67,
"diameter": 24.26,
"thickness": 1.75,
"value": 0.25
}
};
Method 1:
Object.keys(validCoins).forEach(function(coinType) {
alert(coinType.weight);
}
Method 2:
for (var key in validCoins){
//Checking for hasOwnpProperty here doesn't make a difference
alert(key["weight"]);
}
None of these seem to work, it returns undefined, what am I missing? (Do I have to import libraries or something?) I intend to do this using plain javascript.