JavaScript Arrays
<!DOCTYPE html> <html> <body> <h2>map, filter, and reduce</h2> <script> const numbers = [1, 2, 3, 4, 5]; // map: build a new array by transforming each element const doubled = numbers.map((n) => n * 2); console.log(doubled); // [2, 4, 6, 8, 10] // filter: keep only elements that pass a test const evens = numbers.filter((n) => n % 2 === 0); console.log(evens); // [2, 4] // reduce: collapse the array into a single value const total = numbers.reduce((sum, n) => sum + n, 0); console.log(total); // 15 </script> </body> </html>