Skip to content

Instantly share code, notes, and snippets.

@nola
Last active December 29, 2015 14:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nola/7686963 to your computer and use it in GitHub Desktop.
Save nola/7686963 to your computer and use it in GitHub Desktop.
Enumerating over all the properties in an object. Find out whats in there.
//create the object with properties & values.
var myCar = new Object();
myCar.make = "Ford";
myCar.model = "Mustang";
myCar.year = 1969;
//then LOOP(enumerate) through all the properties of the object myCar
function showProps(obj, objName) {
var result = "";
for (var i in obj) {
if (obj.hasOwnProperty(i)) {
result += objName + "." + i + " = " + obj[i] + "\n";
}
}
return result;
}
//then call it
showProps(myCar, "myCar")
@nola
Copy link
Author

nola commented Nov 28, 2013

This is mainly used within the console to see what properties you have access to within the object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment