Last active
December 17, 2015 17:39
-
-
Save bingeboy/5647519 to your computer and use it in GitHub Desktop.
JavaScript Proper methods
This file contains 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
//data type with length | |
var x = [1,2,3,4,5,5,5,5,5,5,5,5,5,5,5,6,7,7,10]; | |
var i | |
,content; | |
for(i = 0; xlength; i < content; i ++){ | |
console.log(x[i]); | |
} | |
//loop through an object literall | |
var statContainer = { | |
"rolledStats" : { | |
"strength" : "7", | |
"dexterity" : "12", | |
"constitution" : "4", | |
"intelligence" : "11", | |
"wisdom" : "16", | |
"charisma" : "9" | |
} | |
}; | |
//proper method to avoid primitive object's prototype. | |
for (var key in statContainer) { | |
if (statContainer.hasOwnProperty(key)) { | |
var obj = statContainer[key]; | |
for (var prop in obj) { | |
if (obj.hasOwnProperty(prop)) { | |
console.log(prop + " = " + obj[prop]); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment