Assuming I have an array which looks like that:
let arr = [{field: ["alice"]}, {field : ["bob", "charlie"]}
I want to be able to concat all values without writing the nested for loops.
I've done this so far:
arr.reduce((a, b) => a.field.concat(b.field))
The problem, as I see this, that the type of the array, lets say arr : Array<MyObject>, is changed when mapping or something similar.
Im getting a TS2345 error
...Is not assignable to parameter of type...
Just to clear things up, the result should be IDENTICAL to the following result.
let result = [];
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].field.length; j++) {
result.push(arr[i].field[j])
}
}
sorry I can't share my real code, but this is the exact issue. This works on Chrome's developer tools for some reason but not when I try to compile my code.