Adding and Removing Items
Use push and pop to change your list.
Adding and Removing 📥📤
Hi, list keeper! 🌟 We can ADD and REMOVE items from a list!
We use .push() to add and .pop() to remove. 🪄
let bag = ["apple"]
bag.push("banana")
console.log(bag)Push to Add 📥
.push() adds a new item to the END of the list!
Like dropping a new treasure into the chest. 💎
let chest = ["gold"]
chest.push("gem")
console.log(chest)All lessons in this course
- What Is an Array?
- Getting Items by Number
- Adding and Removing Items
- Looping Through a List