JavaScript Arrays

Array is a collection of similar types of elements. The JavaScript Array object represents such an array.

Note: We have used the const keyword to create an array since it is generally and widely preferred. The cost introduced in ES6.

Create an Array

Let us see how to create an array in JavaScript. We have created an array of string elements:

Output

Create an array in JavaScript

Access Array elements

To access elements in an array, we use the square brackets. Within that, set the index number. Like Java, the arrays in JavaScript begin with index 0. Therefore, the following access the 1st element from the product array:

Let us see an example to access array elements in JavaScript:

Output

Access array elements in JavaScript

Find the length of an array

To find the length of an array in JavaScript, use the length property. Let us see an example:

Output

Length of an array in JavaScript

Iterate an Array

To iterate an array in JavaScript, we will use the for loop:

Output

Iterate an array in JavaScript

JavaScript Math
JavaScript Date
Studyopedia Editorial Staff
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading