Explore Objects
Objects
Let's explore objects!
Explore:
- Access the value 'USA' from the courseInstructor object.
- Add key-value pairs to the courseInstructor object.
- Write your own object and access and manipulate the values.
// Our courseInstructor objectlet courseInstructor = {name: 'Jeremy',age: 32,livesAround: 'SF Bay Area',country: 'USA'}// Let's access the object and object items// Here is the objectconsole.log(courseInstructor);// Here are two different ways to print a value from given the related keyconsole.log(courseInstructor['name']);console.log(courseInstructor.name);// Here is how to change a valueconsole.log(courseInstructor);courseInstructor.age = 33;console.log(courseInstructor);// Here is how you add a key-value pairconsole.log(courseInstructor);courseInstructor.favColor = 'teal';console.log(courseInstructor);// You can get just the keys or values and put them in arraylet courseInstructorArrayWithValues = Object.values(courseInstructor);console.log(courseInstructorArrayWithValues);// Note that the keys are all strings.let courseInstructorArrayWithKeys = Object.keys(courseInstructor);console.log(courseInstructorArrayWithKeys);