map以及forEach的区别

首先要知道map以及forEach都是用来循环的,然后区别就是map可以又返回值既return,而forEach没有返回值

以下为map和forEach的示例

let arr=[1,2,3,4]
  
  arr.forEach((item,index)=>{
    arr[index] = item+1
  })
  console.log(arr)
 
  arr.map((item,index)=>{
    return index+1
  })
  console.log(arr)
原文地址:https://www.cnblogs.com/wgs-blog/p/14763624.html