I tried doing items.map((item) => arrs.push({item._id:item.word}));
but the first element for the key did not work at all so I instead wrote a basic for loop. Now creating the for loop works fine and console logging arrs after the loop shows the correct information for the values but the keys for all of them show "temp" as a string, instead of the desired id from items[i]._id
. In VS code the temp in let temp=item...
is greyed out and says "temp is declared but its value is never read". Now if I put a console.log(temp)
between let temp...
and arrs.push...
it correctly logs out the value in the temp variable.
const arrs = [];
for (let i = 0; i < items.length; i++) {
let temp = items[i]._id;
arrs.push({ temp: items[i].word });
}
I thought temp was within the same scope so it should work. Have no idea what is happening.
I tried creating different scopes but nothing worked.