Faced strange issue in JS. I receive error on this:
let a = [] let b = [1,2,3] b.forEach(a.push) TypeError: Array.prototype.push called on null or undefined
Because .forEach() supplies to your callback 3 arguments.
.forEach()
callback is invoked with three arguments: the element value the element index the array being traversed
callback is invoked with three arguments:
The .push() can accept any number of arguments. So, on each iteration, .push() adds those three arguments to your array.
.push()