DEV Community

Megan Paffrath
Megan Paffrath

Posted on

Object Literals

Objects are collections of key-value pairs (properties).

To create an object we can do as follows:

let person = {
   firstName: 'Megan',
   isOnVacation: true,
   favFoods: ['plum', 'salad', 'fritos']
}
Enter fullscreen mode Exit fullscreen mode

To access values within the object we can:

console.log(person.isOnVacation); // true
console.log(person['isOnVacation']); // true
Enter fullscreen mode Exit fullscreen mode

We can also make an object that contains objects:

let student = {
   name: 'Jimmy',
   exams: {
      artFinal: 'A',
      mathFinal: 88
   }
}
Enter fullscreen mode Exit fullscreen mode

To access a value in the object's object, we can:

console.log(student.exams.artFinal); // 'A'
Enter fullscreen mode Exit fullscreen mode

Also, we can make arrays containing objects:

let friends = [
   {
      name: 'Sorour',
      favColor: 'blue',
      metAt: 'college'
   },
   {
      name: 'Timothy',
      favColor: 'red',
      metAt: 'Starbucks'
   }
];
Enter fullscreen mode Exit fullscreen mode

To access a value in the second object, we can call:

console.log(friends[1].favColor); // 'red'
Enter fullscreen mode Exit fullscreen mode

To update a value in the second object, we can:

friends[1].name = 'Tim';

console.log(friends[1].name); // Tim
Enter fullscreen mode Exit fullscreen mode

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)