Currently, I am tackling a task that involves taking an array of arrays and reducing it into a single array containing all the elements from each individual array.
Here is the initial array setup:
var array = [[1,2,3],[4,5,6],[7,8,9]]
I managed to solve the problem using the following code:
var new_array = array.reduce(function(prev,cur){return prev.concat(cur);})
Upon logging console.log(new_array)
, the output was as expected:
[1, 2, 3, 4, 5, 6, 7, 8, 9]
However, when I attempted to modify the function like this:
var new_array = array.reduce(function(prev,cur){return prev.concat(cur);},0)
An error occurred:
"TypeError: prev.concat is not a function
This makes me wonder why this error is being triggered.