Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

150
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda