how to add,delete,update property in javascript object 1

how to add,delete,update property in javascript object

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'

Here is what the above code is Doing:
1. We create a variable called favChar and assign it an object.
2. We then change the value of the designation key to ‘Hero of Threat Level Midnight’.

Similar Posts