Skip to content

Instantly share code, notes, and snippets.

@homeslicesolutions-zz
Forked from penguinboy/Object Flatten
Created March 18, 2014 15:47
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 homeslicesolutions-zz/9622794 to your computer and use it in GitHub Desktop.
Save homeslicesolutions-zz/9622794 to your computer and use it in GitHub Desktop.
var flattenObject = function(ob) {
var toReturn = {};
for (var i in ob) {
if (!ob.hasOwnProperty(i)) continue;
if ((typeof ob[i]) == 'object') {
var flatObject = flattenObject(ob[i]);
for (var x in flatObject) {
if (!flatObject.hasOwnProperty(x)) continue;
toReturn[i + '.' + x] = flatObject[x];
}
} else {
toReturn[i] = ob[i];
}
}
return toReturn;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment