📚 › JavaScript: make pages do things
11. Array methods: map and filter
इस लेख का अनुवाद अपने आप होगा। अभी अंग्रेज़ी में दिखाया जा रहा है।
map creates a new array by changing every item. filter keeps only the items that pass a test. Both leave the original array unchanged.
Chaining them reads like a sentence: take the even numbers, then double them.
उदाहरण देखें
const nums = [1, 2, 3, 4];
const evenDoubled = nums.filter(n => n % 2 === 0).map(n => n * 2);
console.log(evenDoubled.join(","));
✍️ अब आपकी बारी
From [1, 2, 3, 4, 5], keep the odd numbers with filter and print them joined with commas.