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.
Example02
Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output
2. Array Constructor : Creates an array using the Array constructor.
Example03
Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

🔸 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.
Example05
Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

🔸 Multidimensional Arrays - Method 1

Create Inner Arrays : Nested 1D arrays to form a 2D structure.
Example06
Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

🔸 Multidimensional Arrays - Method 2 (Array Literals)

Directly declare 2D array using array literals.
Example07
Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

🧠 Test Your Knowledge

5 Questions
Progress: 0 / 5