Arrays
Arrays are used to store multiple values in a single variable:
Common Array Methods:
- push(): Adds an item to the end of an array.
- pop(): Removes the last item from an array.
- shift(): Removes the first item from an array.
- unshift(): Adds an item to the beginning of an array.
- concat(): Combines two or more arrays.
- join(): Creates a string from the array's elements.
- slice(): Returns a shallow copy of a portion of an array.
- splice(): Changes the contents of an array by removing or replacing existing elements.
Example:
const fruits = ["apple", "banana", "orange"];
fruits.push("grape"); // Adds 'grape'
console.log(fruits); // Output: ["apple", "banana", "orange", "grape"]