Today you will learn:
By the end, you will be able to organize data efficiently in JavaScript.
Arrays store multiple values in one variable.
let fruits = ["apple", "banana", "orange"];
console.log(fruits[0]); // apple
Explanation:
[]Objects store related data as key-value pairs.
let person = {
name: "John",
age: 25
};
console.log(person.name); // John
Explanation:
{}You can store objects inside arrays.
let people = [
{ name: "John", age: 25 },
{ name: "Alice", age: 30 }
];
console.log(people[0].name); // John
let fruits = ["apple", "banana", "orange"];
console.log(fruits[0]);
let person = {
name: "John",
age: 25
};
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);