Tutorial
Arrays

Introduction to Arrays

🎉

Read This on Github

This article is available on Github. You can read it there and contribute to it.
Github Link
Any Issue ?

⭐ What is Arrays?

Example with Explanation

Imagine you are building a to-do list application. You would likely use an array to store the list of tasks that need to be completed. The items in the array would be the individual tasks, such as "buy groceries" or "clean the house." You could then use array methods to add, remove, or modify the items in the list as the user interacts with the application.

I'm giving you a simple to-do list feel using an array don't worry we will learn more about it

let taskList = [
  {
    date: 'Monday, January 18',
    tasks: [
      { time: '9:00am', task: 'Meeting with Manager' },
      { time: '2:00pm', task: 'Team Lunch' },
      { time: '5:00pm', task: 'Complete Project Proposal' },
    ],
  },
  {
    date: 'Tuesday, January 19',
    tasks: [
      { time: '10:00am', task: 'Client call' },
      { time: '1:00pm', task: 'Work on Presentation' },
      { time: '3:00pm', task: 'Team Meeting' },
      { time: '7:00pm', task: 'Gym' },
    ],
  },
  {
    date: 'Wednesday, January 20',
    tasks: [
      { time: '9:00am', task: 'Code Review' },
      { time: '11:00am', task: 'Update Wiki' },
      { time: '2:00pm', task: 'Team Standup' },
    ],
  },
];
console.log(taskList);
Then what is Array ? 😥❓

In JavaScript, an array is a data structure that stores a collection of items, which can be of any data type (numbers, strings, objects, etc.).

⭐ Example of Array

Simple Example

📕

You can put any data type in an array. You can even put an array inside another array (called a nested array). You can also put null , true , and false in an array.

📌 Accessing Array Elements

let array = ['subham', 1, 2, null, true, false];
//type one
console.log(array);
//type two
console.log(array[0]);
console.log(array[1]);
console.log(array[2]);
console.log(array[3]);
console.log(array[4]);
console.log(array[5]);
🤔

There are several ways to print and access all the elements of an array in JavaScript: