Home > database >  how to access any element In nested objects in js
how to access any element In nested objects in js

Time:09-13

popup_data = {
    club: {
        type: 'club',
        type_img: {
            header: 'CLUB HEADER',
            img: 'https://source.unsplash.com/random/800x600',
            sub_header: 'CLUB SUB HEADER',
            content: 'TEXT',
            hotspot_position: [5, -1.5, 2.5]
        },
        hotspots_array: [
            {   id: () => this.club.type   '-'   'type_img',
                position: () => this.club.type_img.hotspot_position,
            },
        ]   
    },

How to get type and type_img.hotspot_position from these nested functions

CodePudding user response:

You can access type with popup_data.club.type and hotspot_position with popup_data.club.type_img.hotspot_position

CodePudding user response:

You can use dot notation

console.log(popup_data.club.type_img.hotspot_position)

or you can also use map to print each item separately

popup_data.club.type_img.hotspot_position.map( item => console.log(item) );

CodePudding user response:

let postion = popup_data.club.type_img.hotspot_position

let type = popup_data.club.type
  • Related