I am trying to make a memory game in next js. I am taking a list of letters of the cards and making 2 of each then randomizing them. This part is work. However, because I made a copy of all the object in the array, I no longer have a unique key. I tried two was of adding a key but both failed.
try 1.
const lettersX2 = letters.concat(letters)
.sort(() => Math.random() - 0.5)
.map((card) => ({...card, order: Math.random() }));
the did not seem to do any thing.
Try 2.
const lettersX2 = letters.concat(letters)
.sort(() => Math.random() - 0.5)
.concat(cards.order = Math.random());
this added a new object at the end of the.
How can a add a new unique key to my array?