Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

143
Vistas
Is it possible to have multiple keys point to the same object?

Basically I want to call myList[i] and get the same value for i = 1, 2, 3, 4 then a second value for 5, 6, 7, 8 and so on. I don't really want to copy-paste the value for 1 into 2, 3, 4.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can use an array of objects

const arr = [...Array(4).fill({ value: 1 }), ...Array(4).fill({ value: 3 })];

console.log(arr[0].value);
console.log(arr[2].value);
console.log(arr[4].value);
console.log(arr[6].value);
arr[0].value = 2;
console.log(arr[0].value);
console.log(arr[2].value);
console.log(arr[4].value);
console.log(arr[6].value);

Each element is a reference to the same object.

That's not possible with an array of primitives.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can try using this -

myList[Math.floor((i-1)/4)]

where i = 1, 2, 3, 4 ...

But if i starts from 0, then

myList[Math.floor(i/4)]

Adjust the +/- 1 according to your requirements.

Where 4 is the block size to which you need to divide the array with.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda