Skip to content

Instantly share code, notes, and snippets.

@timgws
Created April 13, 2015 06:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timgws/faf641c10a437d9a396c to your computer and use it in GitHub Desktop.
Save timgws/faf641c10a437d9a396c to your computer and use it in GitHub Desktop.
var myObj = {
fred: { apples: 2, oranges: 4, bananas: 7, melons: 0 },
mary: { apples: 0, oranges: 10, bananas: 0, melons: 0 },
sarah: { apples: 0, oranges: 0, bananas: 0, melons: 5 }
}
var countMe = {}
var obj = 0;
var key;
var a = myObj;
for (key in a) {
subitem = 0;
if (a.hasOwnProperty(key)) {
for (item in a[key]) {
countMe[obj + "" + subitem] = a[key][item]; subitem++;
}
}
obj++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment