-3
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 logs undefined

What am I doing wrong?

alexchenco
  • 53,565
  • 76
  • 241
  • 413

1 Answers1

1

You probably want to use Array.prototype.map:

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

Array.prototype.forEach doesn't return anything.

Here's an exampe for using forEach:

amaList.forEach(function(item){ 
     console.log(item);
});
Amir Popovich
  • 29,350
  • 9
  • 53
  • 99