๐ŸŒ‡DSA
โ† Back
Data StructureBeginner
๐Ÿ“ฆ

Arrays

A row of lockers for your data

โฑ๏ธ 3โ€“5 hours๐Ÿงฉ 10 LeetCode

โœจ Create a free account to track your progress and unlock solutions.

What is it?

An array is like a row of lockers numbered from 0.

  • Each locker has a number (the index) โ€” so you can jump to any locker instantly.
  • You can open any locker quickly if you know its index.
  • The items stay in order from left to right.

In programming, arrays are great when you want fast access and simple iteration.

Variants / Subtypes

  • Static array โ€” fixed size, memory allocated upfront (e.g. Java int[])
  • Dynamic array โ€” can grow automatically, like JavaScript arrays or Python lists

Real-World Examples

Seats in a cinema row
Student marks list
Daily temperatures
Monthly sales figures
Game scoreboard
Shopping product list

Code Example

What this code shows

Start with [1, 2, 3]. Add 4 to the end and 0 to the front, giving [0,1,2,3,4]. Remove from both ends, leaving [1,2,3]. Check if 2 exists, then print each item.

const arr = [1, 2, 3];

arr.push(4);       // add to end   โ†’ [1, 2, 3, 4]
arr.unshift(0);    // add to front โ†’ [0, 1, 2, 3, 4]
arr.pop();         // remove last  โ†’ [0, 1, 2, 3]
arr.shift();       // remove first โ†’ [1, 2, 3]

console.log(arr.includes(2)); // check membership โ†’ true

// iterate and print each item
for (const x of arr) {
console.log(x);  // 1, then 2, then 3
}

Expected Output

true
1
2
3

LeetCode Practice

๐Ÿ’ฌ
Send us a message
We usually reply within 24 hours
500 left
Arrays โ€” DSA Fun | DSA in Plain English