JavaScript forEach方法不能与Arrow函数一起使用

JavaScript forEach方法不能与Arrow函数一起使用,javascript,foreach,arrow-functions,Javascript,Foreach,Arrow Functions,const数组3=[5,10,15,20,25,30,35,40]; 常量函数5=(索引,元素)=>{returnindex+“:“+element}; console.log(array3.forEach(function5))您需要像一样使用.map()。forEach()将始终返回您未定义的,使用map()函数可以获得您期望的结果: const数组3=[5,10,15,20,25,30,35,40]; 常量函数5=(索引,元素)=>{returnindex+“:“+element}; c

const数组3=[5,10,15,20,25,30,35,40];
常量函数5=(索引,元素)=>{returnindex+“:“+element};
console.log(array3.forEach(function5))
您需要像
一样使用
.map()
。forEach()
将始终返回您
未定义的
,使用
map()
函数可以获得您期望的结果:

const数组3=[5,10,15,20,25,30,35,40];
常量函数5=(索引,元素)=>{returnindex+“:“+element};
console.log(array3.map(function5))
您需要像
一样使用
.map()
。forEach()
将始终返回您
未定义的
,使用
map()
函数可以获得您期望的结果:

const数组3=[5,10,15,20,25,30,35,40];
常量函数5=(索引,元素)=>{returnindex+“:“+element};
console.log(array3.map(function5))您需要采取行动。这将返回一个新数组

const
数组3=[5,10,15,20,25,30,35,40],
function5=(索引,元素)=>index+“:”+元素;
console.log(array3.map(function5))您需要采取行动。这将返回一个新数组

const
数组3=[5,10,15,20,25,30,35,40],
function5=(索引,元素)=>index+“:”+元素;
console.log(array3.map(function5))