i've been tinkering , looking @ loops etc, thought there's quicker way this. got lost in lodash docs...
anyway, want run on following object—
{ stuff: { thing1: 'value1', thing2: 'value2', thing3: 'value3' }, something: 'value4' }
—and return:
{ thing1: 'value1', thing2: 'value2', thing3: 'value3', something: 'value4' }
that is, want eliminate stuff
level , have siblings. in easy / terse way, mean. tried _.flatten
, ._flattendepth
work arrays (returns empty array).
thanks
i think best/only bet loop.
function flattenobject(obj, res) { res = res ? res : {}; object.keys(obj).foreach(function(d) { if (typeof obj[d] === 'object') return flattenobject(obj[d], res); res[d] = obj[d]; }); return res; } console.log(flattenobject(a));
Comments
Post a Comment