javascript dotify

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

showing results for - "javascript dotify"
Amanda
02 Oct 2019
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
javascript dot 3fwhat is flat object javascriptproperty values in a method javascriptobject in javascriptjs post to php n objectjs lost propertyflat js for objectanonymous object javaarrays sort java objectbracket notation object javascriptacess property objectjavascript flatten objectjavascript dot notation objectjavascript object inheritanceflat object javascriptflatten object javascript es6js object valid key names property javascripthow to flat object javascriptacccesing property in instance javascriptflatten the object in jsflat javascript objectjs acces object properties squarejs object flattenwhat is flatobject javascriptmdn javascript dot notationuse argument to access object in hssoundplayer c 23 27 objectobject flatten javascriptflatten object javascriptjavascript should properties of objects be stringsjavascript bracket object vs class object hjs how to use dot notation to add property to objectcomputed member access operator javascripthtml element in js dot notationjavascript access object property by keyreference another property in objecthow to flat an object in javascriptjavascript dotify objectjs flatten objectjavascropt object flatbracket notation javascriptjs dot notationreact javascript dotnotation of array of string objectsflatten object javascriptset object dot notation jsobject js flataccesing js object propeties via array syntaxjs flat object flat object jsdot notation to pull from objectdot notation jsjavascript flat objectfor in acces object with bracketsobject flatjavascript dotify