Skip to content

Instantly share code, notes, and snippets.

@vokeio vokeio/flatten-object.js
Last active Oct 9, 2016

What would you like to do?
Flattens a multi level object to a single level object with paths
function flattenObject (object) {
var flatObject = {};
for (var key in object) {
if (!object.hasOwnProperty(key)) continue;
if (object[key] && object[key] === 'Object') {
var childObject = flattenObject(object[key]);
for (var childKey in childObject) {
if (!childObject.hasOwnProperty(childKey)) continue;
flatObject[key + '.' + childKey] = childObject[childKey];
} else {
flatObject[key] = object[key];
return flatObject;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.