theory.js

Arrays & Array Methods

Creating & Modifying Arrays

Arrays store multiple values and can be modified dynamically.

  • Creating an array: `const arr = [1, 2, 3];`
  • Modifying elements using index notation (`arr[0] = 10`).
  • Arrays can hold any data type (numbers, strings, objects, functions).
const fruits = ["Apple", "Banana", "Cherry"];
fruits[1] = "Mango"; // Replaces "Banana" with "Mango"
console.log(fruits); // ["Apple", "Mango", "Cherry"]