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

199
Vistas
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 Respuestas
Responde la pregunta

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 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