let's say I have a model definition like this.
export interface Basicdata {
materialnumber: number;
type: string;
materialclass: string;
}
I furthermore have an array with values, which match exactly the order of the Basicdata model, i.e.
["10003084", "S", "CLIP"]
I am searching for a way to create the object from these values in the array. What I did is creating an empty object and assigning 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];
But surely there is a better, more elegant way to do that, no? I looked into map and reduce but could find a way.
Thank you.