Unit 2: Functions, Data Structures & ArraysLesson #5 / 10

Lesson 5: Array Iterators (map, filter & reduce)

Er. Manoj Kumar β€” AuthorEr. Manoj Kumarβ€’Last Updated: 26 Aug, 2026

1. Modern Functional Array Iteration

ES6 iterators replace verbose for-loops with clean, declarative operations:

  • map(fn): Returns a new array by applying fn to each element.
  • filter(fn): Returns a new array with all elements that pass the Boolean test.
  • reduce(fn, init): Accumulates array values into a single summary output.
  • ⊞HTML5 Web Code (index.html)
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>JS Map & Filter Studio</title>
    </head>
    <body style="background:#17181c; color:#fff; font-family:Arial; padding:30px;">
    <h2>Course Prices Filtered</h2>
    <div id="results"></div>
    <script>
    const courses = [
    { name: "HTML5 Mastery", price: 0, level: "Beginner" },
    { name: "CSS Grid & Flex", price: 0, level: "Beginner" },
    { name: "Advanced React", price: 0, level: "Advanced" }
    ];
    // Map into HTML pills
    const pills = courses.map(c =>
    `<span style="display:inline-block; padding:6px 12px; margin:4px; background:#1f2029; border:1px solid #04AA6D; border-radius:6px; color:#fff;">
    ${c.name} - ${c.price === 0 ? "FREE" : "$" + c.price}
    </span>`
    ).join("");
    document.getElementById("results").innerHTML = pills;
    </script>
    </body>
    </html>

    Interactive Knowledge Check

    Test your understanding of Lesson #5 concepts

    Which array method creates a NEW array populated with the results of calling a function on every element?