Filter Method
π Scenario: You are working on a small online store. You have a list of products with their prices. You want to find only the products that cost less than $20 to show a special discount section.
π― Goal: Build a program that filters the list of products to keep only those with a price less than $20 using the filter method.
π What You'll Learn
Create an array called
products with objects containing name and price properties.Create a variable called
maxPrice and set it to 20.Use the
filter method on products to create a new array called affordableProducts with products priced less than maxPrice.Print the
affordableProducts array to the console.π‘ Why This Matters
π Real World
Filtering lists of items is common in online stores, apps, and data processing to show only relevant information to users.
πΌ Career
Knowing how to use the filter method helps you work with data arrays efficiently, a key skill for frontend and backend developers.
Progress0 / 4 steps