Skip to content

Instantly share code, notes, and snippets.

@ryan-miller
Created July 23, 2013 13:53
Show Gist options
  • Select an option

  • Save ryan-miller/6062504 to your computer and use it in GitHub Desktop.

Select an option

Save ryan-miller/6062504 to your computer and use it in GitHub Desktop.
simple object introspection (not introspection of a simple object)
for (var element in myObject) {
switch (typeof myObject[element]) {
case "string":
console.log(element + ': ' + myObject[element])
break
case "object":
if (Array.isArray(myObject[element])) {
console.log('the next property is an array')
var i = 0
var length = myObject[element].length
for (i; i<length; i++) {
console.log(element + ' index ' + i + ': ' + myObject[element][i])
}
} else {
console.log('element is an object')
}
break
default:
break
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment