JavaScript Beginner Day 7: Arrays & Objects

Goal of this Day

Today you will learn:

By the end, you will be able to organize data efficiently in JavaScript.

Step 1: Arrays

Arrays store multiple values in one variable.


let fruits = ["apple", "banana", "orange"];

console.log(fruits[0]); // apple

Explanation:

Step 2: Objects

Objects store related data as key-value pairs.


let person = {
  name: "John",
  age: 25
};

console.log(person.name); // John

Explanation:

Step 3: Combining Arrays and Objects

You can store objects inside arrays.


let people = [
  { name: "John", age: 25 },
  { name: "Alice", age: 30 }
];

console.log(people[0].name); // John

Practice


let fruits = ["apple", "banana", "orange"];
console.log(fruits[0]);

let person = {
  name: "John",
  age: 25
};

Task

Complete the following tasks:

Example:


// Array of hobbies
let hobbies = ["gaming", "coding", "reading", "sports", "music"];

// Object about yourself
let me = {
  name: "Alex",
  age: 18,
  hobby: "coding"
};

console.log(hobbies);
console.log(me);