Objects Javascript Summary
You have already learned that JavaScript variables are containers for data values. Objects are variables too. But objects can contain many values.
Example of what an object looks like:
const address = { street: { line1: '11 Broadway', line2: '2nd Floor' }, city: 'New York', state: 'NY', zipCode: '10004'. "The Country is": "United States of America" };
Things to remember about objects:
Remember to use a comma after every object. " , "
You can have an object in an object like with street { }.
to access an object in a line we would do the following;
address.state // => which would return a value of 'New York'
But what if we wanted to access '11 Broadway' ??
address.street.line1. // => Targeting each object before line1
But what if we wanted to access the string "The Country is"? We would need a thing called Bracket Notations eg.
address["The Country is"] // => By adding the brackets we can target it properly
Another reason we would use Brackets if is we want to access an object that doesn't have a value like street above. Look at the following code and after it will show you how you access the first cars type:
let cars = [
{"colour": "purple", "type": "minivan", "registration": new Date('2021-01-03'), "capacity": 7 },
{ "colour": "red", "type": "station wagon", "registration": new Date('2022-03-03'), "capacity": 5} ]
console.log(cars[0].type);










