So far, you've learned how to create arrays and access their elements. But what if you need to change an element after the array is created?
You can modify array elements by assigning a new value to a specific index:
let colors = ["red", "blue", "green"];
colors[1] = "yellow";
// Now colors is ["red", "yellow", "green"]This works just like variable assignment, but you're targeting a specific position in the array using bracket notation.
Your store's inventory system has an error. The item at index 1 shows "out of stock", but you just received a shipment of bananas!
Update the inventory array by assigning "bananas" to index 1, then print the corrected inventory with the label "Corrected inventory: ".
No variables
Output (Console)