Reader small image

You're reading from  JavaScript from Frontend to Backend

Product typeBook
Published inJul 2022
Reading LevelBeginner
PublisherPackt
ISBN-139781801070317
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Eric Sarrion
Eric Sarrion
author image
Eric Sarrion

Eric Sarrion is a trainer and a developer as an independent consultant. He has been involved in all kinds of IT projects for over 30 years. He is also a long time author in web development technologies and is renowned for the clarity of his explanations and examples.
Read more about Eric Sarrion

Right arrow

Arrays

Arrays store a collection of data, ordered according to their index. The index is also called the index of the array. It starts at 0 and scales up to the total number of elements in the array, minus 1 (0 to n-1).

Let’s learn how to create an array first.

Creating an array

An array corresponds in JavaScript to an Array class object. We therefore create an array using the new Array instruction.

However, since arrays are widely used in JavaScript programs, it is also possible to create them using a bracket notation [ and ]. This is an easier way to use them without going through the Array class.

Let’s take a detailed look at these two ways to create an array (with brackets and with the Array class).

Creating an array using square brackets [ and ]

The easiest and fastest way to create an array is to use the bracket notation:

Creating an array using square brackets

var tab = ["Element 1", "Element 2", "Element 3"...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
JavaScript from Frontend to Backend
Published in: Jul 2022Publisher: PacktISBN-13: 9781801070317

Author (1)

author image
Eric Sarrion

Eric Sarrion is a trainer and a developer as an independent consultant. He has been involved in all kinds of IT projects for over 30 years. He is also a long time author in web development technologies and is renowned for the clarity of his explanations and examples.
Read more about Eric Sarrion