• Home
  • Python
    • Introduction to Python
    • Python Developer
  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
  • React.js
    • Introduction to React
    • React Developer
  • Interactive Training
  • Pricing
  • Brainstorm
STEMTrainingGrounds
  • Courses
    • Home
    • Python
      • Introduction to Python
      • Python Developer
    • JavaScript
      • Introduction to JavaScript
      • JavaScript Developer
    • React
      • Introduction to React
      • React Developer
  • Interactive Training
  • Pricing
  • Brainstorm

Quick Links

  • About Us
  • Pricing
  • Partnership
  • Brainstorm
  • Terms
  • Privacy
  • Refunds

Courses

  • Python
    • Introduction to Python
    • Python Developer
  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
  • React
    • Introduction to React
    • React Developer

Newsletter

Subscribe to our free monthly newsletter, for a quick update on Python, JavaScript, and React news

© 2025 - 2026 STEMTrainingGrounds. All Rights Reserved.

JavaScript Developer -

Lesson 6 of 40

Lesson Progress: 0%

Lesson Progress: 0%
Lesson Incomplete
← Previous: Iteration - map
Lesson 6 of 40
Next: Iteration - reduce →
Code Example
const numbers = [1, 2, 3, 4, 5, 6];

const evens = numbers.filter(num => num % 2 === 0);

console.log(evens);

Instructions

▼ ← Click the triangle to hide or reveal instructions.

JavaScript Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • The filter() tool goes through your list and asks every number a "Yes" or "No" question.
  • The num => part sets up a test that each number must take to see if it can stay.
  • The => arrow points to the secret rule that decides which items are special enough to be kept.
  • It is like using a sifter at the beach to catch all the pretty seashells while letting the plain sand fall away.
Code Example
const nums = [3, 12, 7, 25, 9];

const small = nums.filter(num => num < 10);

console.log(small);

Instructions

▼ ← Click the triangle to hide or reveal instructions.

JavaScript Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • The filter() tool acts like a security guard that only lets certain numbers into the "VIP" list.
  • The num => part tells the computer to pick up each number one by one to check its size.
  • The => arrow points to your test, which in this case is checking if the number is smaller than 10.
  • It is like sorting through a bin of toys and only picking out the ones that are small enough to fit inside your pocket.
Code Example
const names = ["Alice", "Bob", "Andrew", "Cara"];

const aNames = names.filter(name => name.startsWith("A"));

console.log(aNames);

Instructions

▼ ← Click the triangle to hide or reveal instructions.

JavaScript Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • The filter() tool looks at every name in your list to see if it matches your special search rule.
  • The name => part tells the computer to grab one name at a time so it can look at the first letter.
  • The => arrow points to the startsWith("A") test, which only says "Yes" to names beginning with a capital A.
  • It is like looking through a phone book and using your finger to only stop at the names that begin with the letter A.
Code Example
const people = [
  { name: "Tom", age: 16 },
  { name: "Sara", age: 21 },
  { name: "Mike", age: 18 }
];

const adults = people.filter(person => person.age >= 18);

console.log(adults);

Instructions

▼ ← Click the triangle to hide or reveal instructions.

JavaScript Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • The filter() tool looks inside every person's folder in your list to check if they are old enough to be included.
  • The person => part tells the computer to grab one person's information at a time so it can check their age.
  • The => arrow points to your rule, which checks if the age number is 18 or even higher.
  • It is like a ticket taker at a movie theater who only lets people in if they are tall enough or old enough to see the show.
Code Example
const words = ["hello", "", "world", "", "JS"];

const filled = words.filter(word => word !== "");

console.log(filled);

Instructions

▼ ← Click the triangle to hide or reveal instructions.

JavaScript Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • The filter() tool goes through your list of words and checks if any of them are empty or "blank."
  • The word => part tells the computer to pick up each word one at a time so it can inspect it.
  • The => arrow points to the rule that says "only keep this word if it is NOT empty."
  • It is like cleaning out a toy box and throwing away the empty candy wrappers while keeping all the actual toys.

Test Incomplete

What does the filter() method do?

Question #

1/15

Score

0/0 - 0.0 %