Skip to content

Array

Easy — everyone uses thisGeneral Dev

ELI5 — The Vibe Check

An array is a list of things in order, like a numbered row of boxes. Box 0 holds the first item, box 1 holds the second, and so on. Arrays are the most basic data structure and almost every program uses them. You can loop over them, sort them, and access any item instantly by its number.

Real Talk

An array is an ordered, indexed collection of elements stored in contiguous memory locations (in low-level languages) or as a dynamic structure (in high-level languages). Arrays provide O(1) random access by index, O(n) search, and O(n) insertion/deletion in the middle. In JavaScript, arrays are dynamic and can hold mixed types. In typed languages, arrays are fixed-type.

Show Me The Code

// JavaScript array operations:
const nums = [10, 20, 30, 40, 50];

console.log(nums[0]);        // 10 — index access O(1)
console.log(nums.length);    // 5

nums.push(60);               // add to end O(1)
nums.unshift(0);             // add to start O(n) — shifts all
nums.splice(2, 1);          // remove at index O(n)

const doubled = nums.map(n => n * 2);   // transform
const evens = nums.filter(n => n % 2 === 0); // filter

When You'll Hear This

"Store the results in an array." / "Loop over the array and process each item."

Made with passive-aggressive love by manoga.digital. Powered by Claude.