We have three different ways to access properties in Javascript Objects, all are very useful and can be combined with each other. The methods are:
**.**
with the property: **object.property**
**object['property']**
**const { property } = object**
Let’s see how each syntax works to access properties in objects. And understand when it is reasonable, depending on the situation, to use one way or another.
Table of Contents
Before we understand how to access the properties in objects, let’s see how we can create these objects.
Objects in Javascript are sets of key-values that, unlike arrays, have no defined order.
//{key : value}
{userName: "@EverythingDebug" }
The simplest and most efficient way to create a Javascript Object is using the literal object form with **{}**
. You simply need to create a variable, in the example below I called the variable **myProfile**
, and pass the key-value properties to this variable, very simple.
const myProfile = {
title: "@EverythingDebug",
url: "https://twitter.com/EverythingDebug",
tweets: 9,
followers: 4,
following: 6
};
#javascript