Miguel Buising
2022-06-17T13:13:34Z

Object Flattener

| //@source link [https://stackoverflow.com/questions/44134212/best-way-to-flatten-js-object-keys-and-values-to-a-single-depth-array]
| function flattenObject(ob) {
| var toReturn = {};
|
| for (var i in ob) {
| if (!ob.hasOwnProperty(i)) continue;
|
| if ((typeof ob[i]) == 'object' && ob[i] !== null) {
| 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;
| }