showing results for - "javascript flat object"
Judith
13 May 2017
1Object.assign(
2  {}, 
3  ...function _flatten(o) { 
4    return [].concat(...Object.keys(o)
5      .map(k => 
6        typeof o[k] === 'object' ?
7          _flatten(o[k]) : 
8          ({[k]: o[k]})
9      )
10    );
11  }(yourObject)
12)
13
Laura
22 Nov 2017
1function dotify(obj) {
2    const res = {};
3    function recurse(obj, current) {
4        for (const key in obj) {
5            const value = obj[key];
6            if(value != undefined) {
7                const newKey = (current ? current + '.' + key : key);
8                if (value && typeof value === 'object') {
9                    recurse(value, newKey);
10                } else {
11                    res[newKey] = value;
12                }
13            }
14        }
15    }
16    recurse(obj);
17    return res;
18}
19dotify({'a':{'b1':{'c':1},'b2':{'c':1}}}) //{'a.b1.c':1,'a.b2.c':1}
queries leading to this page
flatten an objectobject js flatacccesing property in instance javascriptfor in acces object with bracketsjs flatten an objectjs flatten objectsoundplayer c 23 27 objectjavascript dot 3fhow to flatten object javascriptflatten an object in jswhat is flatobject javascripthow to flat object jsflatten objectjavascript dot notation objecthow to flatten an object in javascriptjs flatten objecjavascript array objects flatflatten object jsflat object of arrays javascriptobject flattenjs object flattenflatten an object javascriptflat object in javascriptjavascript object flatten javascript access object property by keyflat object javascriptflatten an object in javascriptflatten objects example 2bjavascripthow to flatten objects jscomputed member access operator javascriptdot notation to pull from objectflaten object jsanonymous object java property javascriptflatten object javascript es6html element in js dot notationmdn javascript dot notationhow to flatten an object javascripthow to flat object javascriptjs flate objectjs flat object how to flatten objects in javascriptjs object flatjavascript object inheritancejavascropt object flatobject flatflatten object javascriptdot notation jsjs lost propertyacess property objectobject flattenerflat object jsreact javascript dotnotation of array of string objectsflatten object of objects jsflatten object javascriptbracket notation object javascriptwhat is flat object javascriptflat js for objectjavascript bracket object vs class object hjs how to use dot notation to add property to objectjavascript dotify objectjavascript flat object values arrayja flatten objectobject flattern in jswhat is flatten objectbracket notation javascriptflatten and deflate javascript objectjs object valid key names javascript flat objecthow to flat an object in javascriptflatten javascript objectuse argument to access object in hsset object dot notation jsflattening object javascriptjavascript flatten objectjs code to flatten an objectproperty values in a method javascriptflatten the object in jsobject flat javascriptjavascript should properties of objects be stringsflattening a objectflatten object properties javascriptjs acces object properties squarereference another property in objectbest way to flatten an objectarrays sort java objectobject in javascriptjs flat a objectobject flatten javascriptjs dot notationjs 2b can you flatten objectshow to flatten an object jsflatten a javascript objectflat an object jsjs post to php n objectaccesing js object propeties via array syntaxflat javascript objectjavascript flat object