Why does not reduce?

I do not understand - how it works:

labelsConv = labels.reduce(
 (prev, tec) => {
 Array.isArray(tec) ? prev.push(tec.join(" ")) : prev.push(tec)
 return prev
},
 [] );


But this code

const labelsConv = labels.reduce(
 (prev tec, i) => 
 Array.isArray(tec) ? prev[i]=tec.join(" ") : prev[i]=tec
,
[]
 );


gives the error "TypeError: Cannot assign to read only property '1' of string 'bla bla bla'"
March 12th 20 at 07:56
1 answer
March 12th 20 at 07:58
Solution
In the second case you are returning in colbeck, array prev, and tec.join(" ") or tec
And in the second iteration you get the error, try to change the string property to '1' what actually is written in the text of the error:
TypeError: Cannot assign to read only property '1' of string 'bla bla bla'

Find more questions by tags JavaScript