JS Arrays & Objects

Pascual Vila
Fullstack Instructor // Code Syllabus
A single variable is not enough to build real-world applications. To handle collections of data, you must master the building blocks of JavaScript data structures: Arrays and Objects.
Arrays (Lists)
An Array is a special variable that can hold more than one value at a time. It represents an ordered list.const cars = ["Saab", "Volvo", "BMW"];
Arrays use zero-based indexing. This means the first element is `cars[0]`, the second is `cars[1]`, and so on. They are incredibly useful for iterating over large sets of data.
Objects (Entities)
Objects are variables too, but they can contain many values formatted as key-value pairs (properties). They are perfect for modeling real-world things.const person = { firstName: "John", lastName: "Doe", age: 50 };
You can access an object's properties using Dot notation (`person.age`) or Bracket notation (`person["age"]`). Bracket notation is necessary when property names contain spaces or are stored in variables.
Complex Data (JSON)
When an application communicates with a server, it usually sends data as an Array of Objects. This structure closely mirrors JSON (JavaScript Object Notation), making JS perfectly suited for web APIs.