Hi there, I'm currently learning programming and facing some challenges with arrays in TypeScript. Here are the variables I have:
let nameList: string[] = ['a', 'b', 'c', 'd'];
let postId: number = 1;
My objective is to create a new 2D array:
let newList: (string | number)[][] = [];
in which
newlist = [
[a,1],
[b,1],
[c,1],
[d,1]
]
I have attempted the following:
for (let i: number = 0; i < userList.length; i++) {
newList[i][0].push(userList[i]);
newList[i][1].push(insertID);
}
Additionally,
for (let i: number = 0; i < userList.length; i++) {
newList[i][0] = userList[i];
newList[i][1] = insertID;
}
If anyone could provide assistance on this matter, it would be greatly appreciated! Thank you!