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

201
Visualizações
Reference of array inside another array (not an item of the other array)

This is probably a dumb question but whatever.

If have two arrays like this:

let a = [0,1,2];
let b = [0,1,2,3,4,5];

Is it possible that I can make changes in one happen in the other array as if they are the same place in memory but different lengths like you could in C? (in javascript)

What i want:

a[0] = 1;
console.log(b);
//[1,1,2,3,4,5];
console.log(a);
//[1,1,2];
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Not with plain arrays (unless using getters/setters or proxies to copy the values). However, a shared memory like in C is possible with typed arrays and their subarray method:

const b = Uint8Array.from([0, 1, 2, 3, 4, 5]);
const a = b.subarray(0, 3);
console.log(a, b);
a[0] = 1;
console.log(a, b);

The downside (?) is that you can store only integers in the array, not objects or strings.

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