...

/

Objects and Arrays

Objects and Arrays

Revisit your understanding of objects and arrays, essential tools for structuring and manipulating data in JavaScript.

Objects and arrays are fundamental building blocks in JavaScript. Objects allow us to structure data using key-value pairs, making it easy to represent entities like users, products, or books. Arrays, on the other hand, are perfect for organizing lists of data that need to be iterated or transformed.

Working with objects

Objects in JavaScript are collections of key-value pairs, where keys are strings (or symbols) and values can be any data type, including other objects or functions. This flexibility makes objects a powerful tool for representing real-world entities and organizing complex, hierarchical data. They form the backbone of JavaScript's structure, enabling features like dynamic property access, method invocation, and seamless integration with JSON for data exchange.

Creating and accessing objects

We can create objects using curly braces {} and access their properties using dot notation or bracket notation.

Press + to interact
// Creating an object
const user = {
name: "Alice",
age: 25,
isAdmin: false
};
// Accessing properties
console.log(user.name); // Alice
console.log(user["age"]); // 25

Modifying objects

We can add, update, or delete properties in an object.

Press + to interact
// Adding a property
user.email = "alice@example.com";
// Updating a property
user.age = 26;
// Deleting a property
delete user.isAdmin;
console.log(user);

Iterating through objects

We use for...in loop to iterate over an object’s ...

Access this course and 1400+ top-rated courses and projects.