Objects

PHOTO EMBED

Sun May 02 2021 14:33:36 GMT+0000 (UTC)

Saved by @nata

//1. Assigning 'Value' to 'Property Name' Difference within and outside object
//Inside Object use ':'
let fasterShip = {
  'Fuel Type': 'Turbo Fuel',
  color: 'silver',
}
//Outside Object use '='
fasterShip.color = 'green'
  
//2.Array and Object 
let array = []
let object = {}

//3. Two ways accessing properties
//use '.' or [] depends on if it is one word
let spaceship = {
  homePlanet: 'Earth',
  'Fuel Type': 'Turbo Fuel',
};

spaceship.homePlanet 
spaceship['Fuel Type']

//4. Accessing property using another property 
let spaceship = {
  'Active Mission' : true,
 };
let propName =  'Active Mission';

console.log(spaceship[propName])

//5. Adding new property inside object using '='
let spaceship = {
  'Fuel Type' : 'Turbo Fuel',
  homePlanet : 'Earth',
};
//Adding another property in spaceship 
spaceship.numEngines = 9

//6. Delete property inside object using 'delete'
delete spaceship['Fuel Type']

//7. Array of Objects
let spaceship = {
  passengers: [{
    name: 'Mary',
    name2: 'Kate'
  }],
}
content_copyCOPY