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

137
Vistas
nested JS object and array
let obj = {
    name: 'Kalu Mia High School',
    class: [1, 2, 3, 4, {section: 'A', section: 'B', section: 'C',}, 6, 7, 8, 9, 10],
    pricipal: 'Dhola Mia'
}
console.log(obj)

output : { name: 'Kalu Mia High School', class: [ 1, 2, 3, 4, { section: 'C' }, 6, 7, 8, 9, 10 ], pricipal: 'Dhola Mia' }

In this JS code why I'm not seeing the output like this :

{
  name: 'Kalu Mia High School',
  class: [ 1, 2, 3, 4, {section: 'A', section: 'B', section: 'C' }, 6, 7, 8, 9, 10 ],
  pricipal: 'Dhola Mia'
}

Why this part [ section: 'A', section: 'B',] is missing?

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

0

You have to rearrange the whole thing in your required format. To do that you have to access the data to it's specific position. You did something awkward there in your code at the second array base. you should specify your section somewhere else,maybe the next line. To access it you have to write:

  obj.name //For the school name
about 4 years ago · Juan Pablo Isaza Denunciar

0

Objects are defined like this: {key1: value1, key2: value2} Keys are the identifiers of your values. When you are assigning section: 'A', section: 'B', section: 'C', you are using the same key, so the previous values are overwritten and only the last is stored. That's why it logs 'C'. You can try changing the keys or maybe write it like this: section:['A', 'B', 'C']

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