DEV Community

Siddharth Kanojiya
Siddharth Kanojiya

Posted on

Map, Filter & Reduce in JavaScript # 17

// map() => Create new array by progamining some operation on each array element .

// let arr = [42, 23, 21]
// let a = arr.map((value, index, array )=>{
// console.log(value, index, array)
// return value + 1
// })
// console.log(a)
// // console.log(arr)

// // filter() => filter an array with value that passes a test create a new array

// let arr2 = [42, 23, 21, 0, 3, 5]
// let a2 = arr2.filter((a)=>{
// return a<10
// })
// console.log(a2)

// reduce method --> reduce an array to a single value

let arr3 = [42, 23, 21, 0, 3, 5]
const reduce_func = ((h1, h2)=>{
return h1 + h2
})
let newarr3 = arr3.reduce(reduce_func)
console.log(newarr3)

Top comments (0)