Last active
July 8, 2018 21:50
-
-
Save sevperez/697d7e51ac3a605d52dea82cf48b7584 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var products = { | |
"widget": 400, | |
"gear": 80, | |
"crank": 375, | |
"lever": 870, | |
}; | |
// 1 | |
var productKeys = Object.keys(products); | |
for (var i = 0; i < productKeys.length; i += 1) { | |
var key = productKeys[i]; | |
console.log(key + " : " + products[key]); | |
} | |
// logs "widget : 400", "gear : 80", "crank : 375", "lever : 870" | |
// 2 | |
for (var product in products) { | |
console.log(product + " : " + products[product]); | |
} | |
// logs "widget : 400", "gear : 80", "crank : 375", "lever : 870" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment