let flattenObject = function(ob) {
let toReturn = {};
for (var i in ob) {
if (!ob.hasOwnProperty(i)) continue;
if ((typeof ob[i]) == 'object') {
let flatObject = flattenObject(ob[i]);
for (let x in flatObject) {
if (!flatObject.hasOwnProperty(x)) continue;
toReturn[i + '.' + x] = flatObject[x];
}
} else {
toReturn[i] = ob[i];
}
}
return toReturn;
};
Created
September 21, 2018 13:20
-
-
Save andrit/e45f78699110ab70cc3639e1fcfdb023 to your computer and use it in GitHub Desktop.
Flatten a multidimensional object to one dim
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment