「ES6入門」Map、forEachとfilterのサンプル

1.Map()
const i= 3
const cft = [2, 3, 4, 5, 6]

const result = cft.map(n => n + i)
結果
result = [5, 6, 7, 8, 9]

2.filter()
配列の中から、必要な要素だけ抜き出す
const cft = [1, 2, 3, 4, 5]

const result = cft.filter(m => m < 4)
結果
result = [1,2,3]

3.forEach
const cft = [1, 2, 3, 4, 5]

cft.forEach(item => {
console.log(item)
})

JavaScript

Posted by arkgame