I need to combine 2 arrays read from an excel file into 2-dimensional array, so I can place it as dataSource of material table.
I have these 2 arrays read from excel using XLSX library:
reader.onload = (e) => {
const res = reader.result as string; // This variable contains your file as text
const lines = res.split('\n'); // Splits you file into lines
let ids=[];
let name = [];
let array:any[][];
lines.forEach((line, index) => {
//console.log(line);
ids.push((line.split(',')[0]));
name.push(line.split(',')[1]);
array.push([ids, name])
});
console.log(array);
}
But I keep getting an error on console.log(array):
ERROR TypeError: Cannot read property 'push' of undefined
EDIT:
I changed the code into:
let name = [];
lines.forEach((line, index) => {
//console.log(line);
ids.push((line.split(',')[0]));
name.push(line.split(',')[1]);
array.push(ids, name)
});
console.log(array);
The result was like that:
But that's not what I need because it won't work as dataSource on material table.

let array:any[]=[]