Coding Manifestation Logo
Lesson 13

Arrays Basics

Arrays are used to store multiple values in a single variable. Each value in an array is called an element.

Index010120230340450Elements
  • What is an Array?
  • Creating Arrays
  • Accessing Elements
  • Array Length
  • Common Operations
  • Iterating Arrays

An array is an ordered collection of values. Elements are stored using a zero-based index.

Ordered

Elements have a specific position (index).

Zero-based Indexing

The first element is at index 0.

Holds Any Type

An array can store elements of any data type.

Example
1let numbers = [10, 20, 30, 40, 50];2let fruits = ["Apple", "Banana", "Mango"];3let mixed = [1, "Vivek", true, null];
arr = [10, 20, 30, 40, 50]
Index01234
Value1020304050

First element: arr[0] → 10

Last element: arr[arr.length - 1] → 50

Accessing elements using index.

JavaScript
Output
Your output will appear here...
Use arr[index] to access an element at a specific position.
  • arr[0]
    // First element
  • arr[arr.length - 1]
    // Last element
  • arr.length
    // Total elements
  • arr.push(x)
    // Add at end
  • arr.pop()
    // Remove from end

Loop through each element.

JavaScript
Output
Your output will appear here...

Arrays in JavaScript are dynamic. You can add, remove, and update elements even after creating the array.

PrevNext