javascript dotify object

Solutions on MaxInterview for javascript dotify object by the best coders in the world

showing results for - "javascript dotify object"
Lila
13 Nov 2016
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
bracket notation javascriptcomputed member access operator javascriptreference another property in object property javascriptflat object jsmdn javascript dot notationhow to flat an object in javascriptwhat is flatobject javascriptflat object javascriptjavascript dotify objectaccesing js object propeties via array syntaxjavascript flatten objectacccesing property in instance javascriptobject flatten javascriptjs dot notationflatten object javascriptjavascript object inheritancehtml element in js dot notationflatten object javascripthjs how to use dot notation to add property to objectacess property objectjs post to php n objectjavascript flat object values arrayobject in javascriptjs lost propertyproperty values in a method javascripthow to flat object javascriptjavascript flat objectwhat is flat object javascriptdot notation jssoundplayer c 23 27 objectobject js flatjavascript dot notation objectreact javascript dotnotation of array of string objectsjs flat object js object valid key names javascript bracket object vs class object flat javascript objectjavascript should properties of objects be stringsjavascript dot 3fjavascropt object flatfor in acces object with bracketsobject flatflatten the object in jsbracket notation object javascriptset object dot notation jsanonymous object javause argument to access object in hsjavascript access object property by keyarrays sort java objectdot notation to pull from objectjs flatten objectjs acces object properties squarejs object flattenflat js for objectflatten object javascript es6javascript dotify object