filter and map in javascript code example
Example 1: use .map(), .filter() js
var arr = [1, 25, 20, 4];
var sum = arr.map((item) => item * 10).filter((item) => item > 100);
var sum2 = arr.map((item) => item * 10)
console.log("sum2", sum2)
console.log("sum", sum);
Example 2: map and reduce an array in js
const rebels = pilots.filter(pilot => pilot.faction === "Rebels");const empire = pilots.filter(pilot => pilot.faction === "Empire");
Example 3: js map filter reduce
const numbers = [1, 2, 3, 4];
const doubled = numbers.map(item => item * 2);
console.log(doubled);
Example 4: js map filter reduce
const numbers = [1, 2, 3, 4];
const evens = numbers.filter(item => item % 2 === 0);
console.log(evens);
Example 5: map&filter
const files = [ 'foo.txt ', '.bar', ' ', 'baz.foo' ];
const filePaths = files
.map(file => file.trim())
.filter(Boolean)
.map(fileName => `~/cool_app/${fileName}`);
Example 6: javavscript array.filter with array.map
var arr = [1, 25, 20, 4];
var sum = arr.map((item) => item * 10).filter((item) => item > 100);
var sum2 = arr.map((item) => item * 10)
console.log("sum2", sum2)
console.log("sum", sum);