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?
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
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']