Common array operations
π Scenario: You are working on a small app that manages a list of fruits. You need to perform some common tasks like creating the list, adding a new fruit, filtering fruits by length, and showing the final list.
π― Goal: Build a program that creates an array of fruits, adds a new fruit, filters fruits with names longer than 5 letters, and prints the filtered list.
π What You'll Learn
Create an array called
fruits with the exact values: 'apple', 'banana', 'cherry', 'date', 'fig'Create a variable called
newFruit and set it to the string 'grapefruit'Use the
push method on fruits to add newFruitCreate a new array called
longFruits that contains only fruits with names longer than 5 lettersPrint the
longFruits array using console.logπ‘ Why This Matters
π Real World
Managing lists of items like fruits, products, or tasks is common in apps. Knowing how to add, filter, and display items is very useful.
πΌ Career
Many programming jobs require working with arrays or lists to handle data. These basic operations are foundational skills.
Progress0 / 4 steps