Skip to content

Instantly share code, notes, and snippets.

@bingeboy
Last active December 17, 2015 17:39
Show Gist options
  • Save bingeboy/5647519 to your computer and use it in GitHub Desktop.
Save bingeboy/5647519 to your computer and use it in GitHub Desktop.
JavaScript Proper methods
//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