Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!