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

Chandra Prakash Pal - Feb 24 - - Dev Community

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
. . . . . . . . . . . . . . . .