Assigning Properties
Assigning Properties
- We can use either dot notation, or bracket notation and the assignment operator,
=
to add new key-value pairs to an object or change an existing property
Example
const superHero = {
'secret identity': 'Peter Parker',
name: 'Spiderman',
powers: ['super strength', 'hyper awareness', 'agility', 'genius intellect'],
age: 17
}
// update existing properties
superHero.powers.push('endurance')
superHero.age = 18
// add a new property
superHero.homeCity = 'New York City'
console.log(superHero)
JS Bin on jsbin.com