📌  相关文章
📜  如何在 javascript 对象中添加、删除、更新属性 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:51.107000             🧑  作者: Mango

代码示例1
var brooklynNineNine = {
  name: 'Raymond Holt',
  currentRole: 'Captian of brooklyn99',
}
brooklynNineNine.husband = 'Kevin' // Or brooklynNineNine['husband'] = 'Kevin'

var list =
{
  name: 'Michael Scott',
  company: 'Dunder Mufflin',
  designation: 'Regional Manager',
  show: 'The Office',
},
  new_obj = { ...list, partner: 'Holly Flax' }

var brooklynNineNine = {
  name: 'Amy Santiago',
  currentRole: 'Detective brooklyn99',
  husband: 'Jake Peralta',
  mentor: 'Raymond Holt'
}

delete brooklynNineNine.mentor;

var favChar = {
  name: 'Michael Scott',
  company: 'Dunder Mufflin',
  designation: 'Regional Manager',
  show: 'The Office'
}

favChar.designation = 'Hero of Threat Level Midnight'