Esto es lo que quiero:
Tengo la first
matriz y tengo el index
de la siguiente manera:
const first = ['a','b','c']; const index = 1; // the index of b const shuffled = ['c','a','b']; // now the index of b is 2
En la first
matriz, el index
apunta al segundo elemento de la matriz, que es b
, ¿verdad?
Ahora mezclé la first
matriz y tenemos la matriz shuffled
.
El índice de b
es 2 en este momento. Quiero devolver este nuevo índice...
Usando Array#indexOf
:
const first = ['a','b','c']; const index = 1; const shuffled = ['c','a','b']; const target = first[index]; const newIndex = shuffled.indexOf(target); console.log(newIndex);
Puedes usar,
Sea valor = primero[índice]
let newValue =shuffled.indexof(valor)
puedes usar shuffled.indexOf(first[index])
first[index]
devuelve el valor del first index
en este caso 'b'
shuffled.indexOf('b')
devolvería el índice de b en la matriz shuffled