Updating javascript object property?

后端 未结 8 1934
盖世英雄少女心
盖世英雄少女心 2021-02-01 03:26

I have a structure like the following:

skillet.person = {
  name: {
    first: \'\',
    last: \'\'
  }, 
  age: {
    current: \'\' 
  },
  birthday: {
    day:         


        
8条回答
  •  渐次进展
    2021-02-01 03:38

    I think that is simpler

         let skillet = {
            person: {
                name    : {
                    first: '',
                    last : ''
                },
                age     : {
                    current: ''
                },
                birthday: {
                    day  : '',
                    month: '',
                    year : ''
                }
            }
        };
    
        let update = {
            person: {
                name: {
                    first: 'blah',
                    last : 'ha'
                }
            }
        };
    
        let result = Object.assign(skillet.person, update.person);
    
        console.log(result);
    

提交回复
热议问题