Assume we have a model defined as follows.
export interface Basicdata {
materialnumber: number;
type: string;
materialclass: string;
}
We also have an array containing values that correspond directly to the Basicdata model in order, like this:
["10003084", "S", "CLIP"]
I am exploring ways to create an object using these array values. One approach is to initialize an empty object and populate it with the array values.
const singleRow = rows[0];
const newBD: Basicdata = {
materialnumber: 0,
type: '',
materialclass: '',
}
newBD.materialnumber = singleRow[0];
newBD.type = singleRow[1];
newBD.materialclass = singleRow[2];
However, I believe there must be a more elegant solution to accomplish this. I have tried to use map and reduce but haven't found a suitable method yet.
Any suggestions would be appreciated.