該方法能夠看爲映射關係數組
let arr = [1,2,3,4,4,6,7] let result = arr.map(item => item*3 ) console.log(result) // 具體例子 let score = [50,54,60,70] let rank = score.map(item => item>=60?'合格':'不合格') console.log(rank)
// 數組中的reduce方法 能夠當作彙總 let arr = [1,3,4,5] let result = arr.reduce((pre,next) => pre+next) console.log(result)
fliter 爲過濾方法code
// 數組中的filter 方法 let arr = [1,3,4,5,56,] let result = arr.filter(item => item>4) console.log(result) // 能夠用在過濾一些本身不要的數據上
該方法爲循環遍歷it
let arr = [1,2,3,45,3] arr.forEach((item, index) => { console.log(item, index) });