Question
Angular: pull sub array values into main object with dynamic subarray
I'd like to pull sub array values into my main object. The subarray size is dynamic.
Starting with this:
myArray = [{'ID' : 1,
'addDetail' : ['test 1', 'test 2']}]
I expect this array:
myArray = [{'ID' : 1, 'line1' : 'test 1', 'line2' : 'test 2'
'addDetail' : ['test 1', 'test 2']}]
I tried the below code:
this.partiesdatalist = this.partiesdatalist.map(item => {
const addDetail = item.addDetail;
addDetail?.forEach((detail, index) => {
item[`line${index + 1}`] = detail;
});
return item;
});
but it produces this error:
Element implicitly has an 'any' type because expression of type '
line${number}
' can't be used to index type
On this line:
item[`line${index + 1}`] = detail;