Avatar of mikha
mikha
Flag for United States of America

asked on 

es6 javascript string interpolation - array within array

I have a json array that i get back from a ajax call. I loop over the data and append it to HTML , this works fine. Now I want to add the list of siblings as a list , which is an array item.family.siblings.

I have used string interpolation below with es6, how can i iterate through the list of siblings below, any suggestions?

     $.each(this.results, (index, item) => {
       let newitem = documment.createElement('div');

       newItem.innerHTML = `<div>
                                                      <span>Name</span><span>${item.name}</span>
                                                       <span>Father</span><span>${item.family.father}</span>
                                                      <span>Mother</span><span>${item.family.mother}</span>
                                                      <ul><span>Siblings</span>
                                                              <li>
                                                      </ul>
                                                       
                                             </div>`  ;

       this.listcontainer.append ( newItem)

     });

{  
  "results" : [
                        { 
                           name : "adam" , 
                           family : {
                                               siblings: [
                                                                    {"relation" : "sister" , "name":"jennifer"},
                                                                    {"relation" : "brother" , "name":"john"}
                                                            ], 
                                               mother : "janet",
                                               father : "thomas"
                                           }
                         }, 
                         { 
                           name : "johnathon" , 
                           family : {
                                               siblings: [
                                                                    {"relation" : "brother" , "name":"scott"},
                                                                    {"relation" : "brother" , "name":"chuck"}
                                                            ], 
                                               mother : "debby",
                                               father : "shawn"
                                           }
                         },
                         ....

                       
                     
  ]
}

Open in new window

HTMLJavaScriptAJAXJSON

Avatar of undefined
Last Comment
mikha

8/22/2022 - Mon