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
}
};
Approach 1:
Object.keys(validCoins).forEach(function(coinType) {
alert(coinType.weight);
}
Technique 2:
for (var key in validCoins){
//Checking for hasOwnpProperty here doesn't make a difference
alert(key["weight"]);
}
Neither of these techniques seems to be working as expected, returning undefined values. What could be the issue? Do I need to include any libraries or dependencies? My objective is to achieve this using vanilla JavaScript.