
What is Array
In JavaScript, an array is a data structure that allows you to store multiple values in a single variable. Arrays can hold a collection of any type of data, including numbers, strings, objects, or even other arrays (nested arrays).
Characteristics of Arrays:
Creating an Arrays:
const fruits = ["apple", "banana", "cherry"];const numbers = new Array(1, 2, 3, 4);Accessing Array Elements
Each element in an array is assigned a numeric index, starting from 0. You can access an element using its index.
const colors = ["red", "green", "blue"];
console.log(colors[0]); // Output: "red" (1st element)
console.log(colors[2]); // Output: "blue" (3rd element)If you try to access an index that doesnβt exist, it returns undefined.