I am trying to push the array into another array. The data is filling in the parent array, but after filling the records, it's overwriting all records in the parent array. Here I have written my code. Please guide me on where I am making a mistake?
Here I am trying to make a model like CSV file header values as a key and CSV file records as a value.
let csvArr: any[] = [];
for (let i = 1; i < csvRecordsArray.length; i++) {
let curruntRecord = (<string>csvRecordsArray[i]).split(',');
if (curruntRecord.length == headerLength) {
let headerRecord: {};
headerRecord = this.headersRowData
for(let j = 0; j < this.headersRowData.length; j++){
headerRecord[this.headersRowData[j]] = curruntRecord[j].trim()
}
csvArr.push(csvRecord)
}
}
HeaderRowData will read the header from the CSV file which is an array type of any[].
csvRecord is getting proper data as per file and loop but while push in csvArr then all existing records in csvArr is overwriting there. So how to resolve this overwriting issue here?