Array Filter and Map in JavaScript
Level 3117 keystrokes
Method chaining allows combining filter and map operations on arrays.
JavaScript code
// Create an array of numbers1const nums = [1, 2, 3, 4, 5, 6];// Chain filter and map on nums2const result = nums // filter keeps only even numbers (n % 2 === 0): 2, 4, 63 .filter(n => n % 2 === 0) // map doubles each remaining number: [4, 8, 12]4 .map(n => n * 2);// Print the final result5console.log(result);Output
[ 4, 8, 12 ]
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this JavaScript code and how often they appear.
=× 7,× 5;× 3.× 3(× 3)× 3>× 2[× 1]× 1*× 1