Objects and Arrays
Tags: javascript
Published: 2021-01-12 16:42:24

## Objects IronHack Document </a>
#### Objects are commonly used as a median to assign larger amounts of data </a>
### Objects are a collection of properties and those properties are represented by key Value pairs </a>
#### A key-value pair is a string that identifies as a property and corresponds to a value. </a>
``` Java
let weeklySchedule = {
monday: 7-12
tuesday: 7-11
wednesday: 7-4
thursday: 7-3
friday: 7-9
}
```
#### "monday", "tuesday" etc.. are the keys that are assigned number values using ":" </a>
#### In the "weeklyschedule" object I used object literal syntax, i used "{}" to create the object. </a>
### Accessing the Values in Objects, in order to display the values inside an object you must log it into the console like so: </a>
``` Java 
console.log(weeklyschedule);
```
#### Changing property values </a>
#### We can change the value of a property after it is defined using dot notation: </a>
``` Java
let workHours = {
mon: 8-4
tues:8-4
wed: 10-4
thurs:8-4
fri:8-4
}
workHours.wed = 12-4;
```
#### Another method of changing values is bracket notation: </a>
``` Java
let workHours = {
mon: 8-4
tues:8-4
wed: 10-4
thurs:8-4
fri:8-4
}
workHours[tues] = 12-8;
```
#### The "in" operator, this operator can be used to determine if a certain property exists in an object: </a>
``` Java
let workHours = {
mon: 8-4
tues:8-4
wed: 10-4
thurs:8-4
fri:8-4
}
'mon' in workHours // true
'sat' in workHours // false
```
#### You can remove properties using "delete": </a>
``` Java 
let favoriteCarBrand = {
make1: 'Ferrari'
make2: 'Honda'
make3: 'Nissan'
}
delete favoriteCarBrand.make1 // dot method
delete favoriteCarBrand['make1'] // bracket method
```
#### Listing Properties </a>
#### One method is "Object.keys()", another method is "for...in loop": </a>
``` Java
let favoriteCarBrand = {
make1: 'Ferrari'
make2: 'Honda'
make3: 'Nissan'
}
Object.keys(favoriteCarBrand) // object.keys method
for(let key in favoriteCarBrand){
console.log(key); // for in loop method
}
```
## Arrays and Objects IronHack Document </a>
#### Arrays and Objects are some examples of data structures, a data structure is a specific way of storing data </a>
#### In certain situations you can use arrays inside of objects to increse productivity: </a>
``` Java 
let finalProjectGroups = {
['John', 'Alyssa', 'Robert']
['Isabella', 'Dylan', 'Alejandro'] 
['Jorge', 'Nicolas', 'Daniel']
}
```
#### Some objects are known as complex objects for the amounts of data they hold for example:
``` Java
let peopleInTennisLessons = {
{ firstname:'Alejandro', lastname;'Rodriguez' age: 24 }
{ firstname:'Alyssa', lastname;'Garcia' age: 21 } 
{ firstname:'Alex', lastname;'Garcia' age: 15 }
{ firstname:'Darian', lastname;'Alexi' age: 18 }
```
#### Objects inside of Objects </a>
#### When you create an object in an object the way you access it changes, lets create an object inside an object and access it: </a>
``` Java
let virtualClassroom2 = {
teacher: { firstname:'Alberto' lastname:'Garcia' age:35
};
console.log(virtualClassroom2.teacher) / * this shows all values in "teacher" * /
console.log(virtualClassroom2.teacher.age) / * this is how you access values in an object inside of an object * /
}
```
## Udemy Net Ninja Section 5 </a>