How to use the Brackets notation In Javascript
Using bracket notation and the object’s desired index, you can access an object in an array. In type, the whole object is accessed and only one of the properties of a specific object can’t be accessed.
Syntax:
arrayName[arrayIndex]
Example: The code below demonstrates how we can use the brackets notation to access the elements of the array of objects.
Javascript
// Array of objects let objArr = [ { name: 'john' , age: 12, gender: 'male' }, { name: 'jane' , age: 15, gender: 'female' }, { name: 'julie' , age: 20, gender: 'trans' } ]; console.log( "First Object in the Array using the [] notation:" ) console.log(objArr[0]); |
Output
First Object in the Array using the [] notation: { name: 'john', age: 12, gender: 'male' }
How to Access Array of Objects in JavaScript ?
In this article, we are going to learn how we Access an Array of Objects in JavaScript. An array of objects in JavasScript is a collection of elements that individually hold a number of properties and values.
The approaches to access the array of objects in JavaScript are:
Table of Content
- Using the Brackets notation
- Using the DOT notation
- Using the for..in loop
- Using forEach Loop
- Using map() method
- Using filter() method