为什么以下 forEach 数组循环未返回未定义

Why isn't the following forEach array loop returning undefined?

本文关键字:返回 未定义 循环 数组 forEach 为什么      更新时间:2023-09-26
var amaList = ['announce', 'argue', 'demonstrate', 'express', 'hint', 'illustrate', 'imply', 'make', 'mean', 'pinpoint', 'point out', 'prove', 'reveal', 'show', 'signal', 'specify', 'suggest', 'attest', 'connote', 'denote', 'designatesta']
var hintList = amaList.forEach(function(s) {
  return s
})
console.log(hintList)

hintList日志undefined

我做错了什么?

您可能

想使用 Array.prototype.map:

var hintList = amaList.map(function(item) {
     //do something with item and return the wanted item
});

Array.prototype.forEach 不返回任何内容。

以下是使用 forEach 的考试:

amaList.forEach(function(item){ 
     console.log(item);
});