Answers for "accessing nested objects in javascript"

0

js create nested object from fields

function assign(obj, keyPath, value) {
   lastKeyIndex = keyPath.length-1;
   for (var i = 0; i < lastKeyIndex; ++ i) {
     key = keyPath[i];
     if (!(key in obj)){
       obj[key] = {}
     }
     obj = obj[key];
   }
   obj[keyPath[lastKeyIndex]] = value;
}
Posted by: Guest on March-19-2021
0

accessing nested objects in javascript

const user = {
    id: 101,
    email: '[email protected]',
    personalInfo: {
        name: 'Jack',
        address: {
            line1: 'westwish st',
            line2: 'washmasher',
            city: 'wallas',
            state: 'WX'
        }
    }
}

const name = user.personalInfo.name;
const userCity = user.personalInfo.address.city;
Posted by: Guest on January-14-2022
0

js create nested object from fields

var settings = {};
assign(settings, ['Modules', 'Video', 'Plugin'], 'JWPlayer');
Posted by: Guest on March-19-2021

Code answers related to "accessing nested objects in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language