Simple example of pushing to an array in javascript.
const soda = ["coke", "sprite", "fanta"];
const length = soda.push("root beer");
console.log(soda);
// output: ["coke", "sprite", "fanta", "root beer"]
push
doesn’t directly modify the variable, so you can use a const
.push
returns the updated length of the array.push
can take more than 1 item at a time:const food = ["hamburger", "hot dog"];
const length = food.push("pizza", "steak", "grilled cheese");
console.log(food);
// output: ["hamburger", "hot dog", "pizza", "steak", "grilled cheese"]
For other javascript examples: https://www.mikesallese.me/tags/javascript