DEV Community

Chandra Prakash Pal
Chandra Prakash Pal

Posted on

Filters even numbers from an array, squares them, and prints the result.

This script defines an array of numbers and filters out the even numbers.
It then squares the filtered even numbers and stores them in a new array.
Finally, it outputs the squared even numbers to the console.

let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
let newArr = arr.filter(function(num) {
  return num % 2 == 0
}).map(function(num) {
  return num * num
})
console.log(newArr)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)