Sorry about this really stupid question, but why this code is not working?
var ar = [1,2,3];
ar.forEach(console.log);
Thank you in advance.
Sorry about this really stupid question, but why this code is not working?
var ar = [1,2,3];
ar.forEach(console.log);
Thank you in advance.
Because You need to pass to the .forEach an anonymous function:
ar.forEach(function(el, index, array){
console.log(index);
});
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach