2
I need to take an object from within an array and send that same object to another array. See:
todasAsCartas:[
{ id: 1, valor: 2, naipe: 'Paus' }, { id: 2, valor: 2, naipe: 'Copas' }, { id: 3, valor: 3, naipe: 'Espadas' }, { id: 4, valor: 2, naipe: 'Ouros' },
{ id: 5, valor: 3, naipe: 'Paus' }, { id: 6, valor: 3, naipe: 'Copas' }, { id: 7, valor: 3, naipe: 'Espadas' }, { id: 8, valor: 3, naipe: 'Ouros' },
{ id: 9, valor: 4, naipe: 'Paus' }, { id: 10, valor: 4, naipe: 'Copas' }, { id: 11, valor: 4, naipe: 'Espadas' }, { id: 12, valor: 4, naipe: 'Ouros' },
{ id: 13, valor: 5, naipe: 'Paus' }, { id: 14, valor: 5, naipe: 'Copas' }, { id: 15, valor: 5, naipe: 'Espadas' }, { id: 16, valor: 5, naipe: 'Ouros' },
{ id: 17, valor: 6, naipe: 'Paus' }, { id: 18, valor: 6, naipe: 'Copas' }, { id: 19, valor: 6, naipe: 'Espadas' }, { id: 20, valor: 6, naipe: 'Ouros' },
{ id: 21, valor: 7, naipe: 'Paus' }, { id: 22, valor: 7, naipe: 'Copas' }, { id: 23, valor: 7, naipe: 'Espadas' }, { id: 24, valor: 7, naipe: 'Ouros' },
{ id: 25, valor: 8, naipe: 'Paus' }, { id: 26, valor: 8, naipe: 'Copas' }, { id: 27, valor: 8, naipe: 'Espadas' }, { id: 28, valor: 8, naipe: 'Ouros' },
{ id: 29, valor: 9, naipe: 'Paus' }, { id: 30, valor: 9, naipe: 'Copas' }, { id: 31, valor: 9, naipe: 'Espadas' }, { id: 32, valor: 9, naipe: 'Ouros' },
{ id: 33, valor: 10, naipe: 'Paus' }, { id: 34, valor: 10, naipe: 'Copas' }, { id: 35, valor: 10, naipe: 'Espadas' }, { id: 36, valor: 10, naipe: 'Ouros' },
{ id: 37, valor: 11, naipe: 'Paus' }, { id: 38, valor: 11, naipe: 'Copas' }, { id: 39, valor: 11, naipe: 'Espadas' }, { id: 40, valor: 11, naipe: 'Ouros' },
{ id: 41, valor: 12, naipe: 'Paus' }, { id: 42, valor: 12, naipe: 'Copas' }, { id: 43, valor: 12, naipe: 'Espadas' }, { id: 44, valor: 12, naipe: 'Ouros' },
{ id: 45, valor: 13, naipe: 'Paus' }, { id: 46, valor: 13, naipe: 'Copas' }, { id: 47, valor: 13, naipe: 'Espadas' }, { id: 48, valor: 13, naipe: 'Ouros' },
{ id: 49, valor: 14, naipe: 'Paus' }, { id: 50, valor: 14, naipe: 'Copas' }, { id: 51, valor: 14, naipe: 'Espadas' }, { id: 52, valor: 14, naipe: 'Ouros' },
]
I need to take one of these objects from this array "all: [ ]"...
Does anyone have any idea how to solve this in Javascript?
Excellent @Michaelpacheco!
– Wees Smith
Dude, that’s it.. It only lacked a "const letter = 0" at the beginning there before the for. It worked here. Ball show. Thank you.
– cardosodiaseduardo2
Glad it worked. No need for a
const carta = 0
outside thefor
. The lineconst cartaAleatoria = cartasNaMesa[numeroAleatorio];
already solves the problem :)– Michael Pacheco