Updating javascript object property?

后端 未结 8 1998
盖世英雄少女心
盖世英雄少女心 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:44

    If you want to mix an object into another one, you can use jQuery's deep extend function. "Deep" means that it does not overwrite name with the new object, but rather overwrites the properties inside such an object.

    $.extend(true, skillet.person, {
      name: {
        first: 'updated'
      },
      birthday: {
        day: 'updated',
        year: 'updated'
      }
    });
    

    Now, skillet.person has the appropriate properties updated, while the other properties are untouched.

提交回复
热议问题