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

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

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

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