JavaScript Arrays
Arrays are used to store multiple values in a single variable.
Creating an Array
You can create an array using square brackets []:
let fruits = ["Apple", "Banana", "Cherry"];
Accessing Array Elements
Array elements are accessed using their index (starting from 0):
console.log(fruits[0]); // Output: Apple
console.log(fruits[1]); // Output: Banana
Common Array Methods
push: Add an element to the end of the array.pop: Remove the last element from the array.length: Get the number of elements in the array.
Example:
fruits.push("Orange");
console.log(fruits); // Output: ["Apple", "Banana", "Cherry", "Orange"]
console.log(fruits.length); // Output: 4