I have a strange problem with [].forEach in NodeJS.
(Using NodeJs v5.4.1)
Enter this code in the function
function _buildUserQuestionsForDisplay(question,callback){ var res = {} ["is_open","created","deleted","_id"].forEach(function(v){ res[v] = question[v] }) ... ... }
Throwing an error:
["is_open", "created", "deleted", "_ ID"]. Foreach (function (v) {
TypeError: cannot read 'forEach' property from undefined
It works if I change the code to
var arr = ["is_open","created","deleted","_id"]; arr.forEach(function(v){ res[v] = question[v] })
I tested the same function on Chrome.console and the first method works.
I know that both using the V8 JS engine, is this a bug or something that I am missing with Javascript rules?
thanks!
source share