Nearby lessons

33 of 40

๐Ÿ“š JavaScript Arrays

๐Ÿ“Œ What are JavaScript Arrays?

JavaScript Array is a single variable that is used to store elements of different data types. Arrays are zero-indexed and are used when we have a list of items to manage.

JavaScript supports one-dimensional and multidimensional arrays (via arrays inside arrays).

๐Ÿ”ธ Array Declaration Methods

1. Array Literal : Creates an array using square brackets.
Code Example
PREVIEW READY
Loading Editor...
Live Preview
2. Array Constructor : Creates an array using the Array constructor.
Code Example
PREVIEW READY
Loading Editor...
Live Preview

๐Ÿ”ธ One-Dimensional Arrays

AttributeValueDescription
Empty Arrayvar arr = [];Declares an empty 1D array.
With Alphabetsvar arr = ["A", "B", "C", "D"];Array of alphabets.
With Numbersvar arr = [1, 2, 3, 4, 5];Array of numbers.
Code Example
PREVIEW READY
Loading Editor...
Live Preview

๐Ÿ”ธ Multidimensional Arrays - Method 1

Create Inner Arrays : Nested 1D arrays to form a 2D structure.
Code Example
PREVIEW READY
Loading Editor...
Live Preview

๐Ÿ”ธ Multidimensional Arrays - Method 2 (Array Literals)

Directly declare 2D array using array literals.
Code Example
PREVIEW READY
Loading Editor...
Live Preview

๐Ÿง  Test Your Knowledge

5 Questions

Progress: 0 / 5
Keep Going!JS - Array Methods