I am attempting to transform an object with arrays as properties into a single array containing all elements from these nested arrays.
My approach is as follows:
data1 = [{
a: 1,
b: ["uz", "vy"]
}, {
a: 2,
b: ["wxa", "xwy"]
}, {
a: 6,
b: ["ysa", "zaa"]
}]
data1.reduce(function(q, w) {
return q.b.concat(w.b)
})
The desired output should be:
data1 = ["uz","vy","wxa","xwy","ysa","zaa"]
However, I encounter the following error message:
"Uncaught TypeError: Cannot read property 'concat' of undefined"
If q.b
references an array within an object, why does it not have the property concat
?
Where did I make a mistake in this code?