How to usesquare bracket notation in Javascript
You can access elements in an array by using their index, where the index starts from 0 for the first element. We can access using the bracket notation.
Example: This example shows the use of the above-explained approach.
const array = [10, 20, 30, 40, 50];
const GFG = array[3];
console.log(GFG);
Output
40
JavaScript Program to Access Elements in an Array
In this article, we will learn how to access elements in an array using JavaScript. The Arrays in JavaScript are zero-indexed which means the first element is accessed using index 0 and the second element with index 1 and so on. Accessing elements in an array is a fundamental operation and is essential for various programming tasks.
Below are the following approaches through which we can access elements in an array using JavaScript:
Table of Content
- Using square bracket notation
- Using loop(for or forEach or for…of) Method
- Using map() Method
- Using find() Method
- Using Destructuring Assignment
- Using filter Method