Search⌘ K

Accessing Object Properties

Explore how to access and manipulate properties within JavaScript objects using dot and bracket notation. Understand accessing nested object properties, using the for..in loop to iterate over properties, and calling functions inside objects. This lesson helps build a solid foundation for working with object data efficiently.

There are various ways to access object properties. We will discuss each method in detail below.

Dot Operator

In JavaScript, an object literal can be accessed using the dot operator. To access any property, the name of the object should be mentioned first, followed by the dot operator and then the name of the property encapsulated in that object.

Example

Let’s take a look at an example:

Javascript (babel-node)
//creating an object named shape
var shape = {
//defining properties of the object
//setting data values
name : 'square',
sides : 4
}
//accessing the properties using the dot operator
console.log("Name is:", shape.name) //using dot operator to access "name"
console.log("Number of sides are:", shape.sides) //using dot operator to access "sides"
...