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

86
Vistas
Javascript circular object array when assigning object to more than one array element

Could someone please explain why this doesn't work and populates the array with "circular object Array"s when there are no circular references? I know there are a million ways to do this better, and I do not plan on using this code, but I really want to know why it doesn't work. I know it must have something to do with how JS passes references, but am confused on what limit we are hitting here.

 const sub = [{1: 2}, {3: 4}, {5: 6}]
const sub2 = [{7: 8}, {9: 0}, {11: 12}]
const sub3 = [{12: 13}, {14: 15}, {16: 17}]
const o = [ {label: 'a', submenu: sub}, {label: 'b', submenu: sub2} ]
console.log(o)
    
o.forEach((currentValue, index, arr) => {currentValue.click = sub3})
    
console.log(o)

about 4 years ago · Juan Pablo Isaza
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