How Can I Access Object in Array Within Array


How can i access of object in Array within Array?

Complicated Question Right?
Please check below:

In the above image in console.log i get the data within [{…}] which i can access it easily but i don’t know how do i access to the data which is inside sub_item which has Array[5].

I want to show the sub_item Details in the list marked in image. Please Help!!


Hi @harshm90,

For example, you can access the sub_item_id of the first subitem (underlined in your example) with data[0].sub_item[0].sub_item_id, assuming that your array is called data.

If you’re asking about showing them in an Angular template, you can do something like this:

<ion-item-group *ngFor="let item of data">
  <ion-item *ngFor="let subitem of item.sub_item">
    <ion-label>{{ subitem.sub_item_name }}<ion-label>

Then it’s your choice to use FormBuilder or ngModel to get the values, ids or whatever you need from the selections.


1 Like

Thank you for the instant reply and help.

You are partially right. Somehow I cracked it.
all I needed to do is mentioning the 0th element of array
instead of this

this.items =[0].sub_item[0].sub_item_id,

in .ts file i needed to write it like

this.items =["0"].sub_item;

and in html file

<ion-item no-lines *ngFor="let addonitem of item" style="font-size: 12px;">
      <ion-checkbox item-left>

and it worked :slight_smile:

1 Like

Awesome! Glad to help :blush:

1 Like