I am trying to understand/comprehend .forEach
loop in Javascript.
Now, I get it simply
let numberArray = [1, 2, 3, 4]
numberArray.forEach(x => {
console.log(x)
})
As expected it would return output
1
2
3
4
Now, Since forEach is a function, I decided to return something and store its value
let numberArray = [1, 2, 3, 4]
let newNum = numberArray.forEach(x => x)
console.log(newNum)
This is returning undefined
when I am clearly returning something and it again it is a function.
Can someone tell me what am I missing here? I mean I the background of forEach loop
[Update:] I know many other ways to achieve my goal, I am more interested to know more about this behaviour for forEach