Search code examples
javascriptarraysjavascript-objects

Ajax DOM javascript loop an array into another one


In my javascript code i have an array like thisone:

enter image description here

i would to loop into first note and loop inside into 'mtitoli' inner array for extract its 'ttipo' and 'tdescr' values i try this code:

$.each(value, function(index, value) {  
    $.each(value['meds'][index].mtitoli, function(titind, titval) {
        console.log("Titoli " + titval);
    })
})

but i get just [Object object] as response.

How can i extract values from array inside my array??

So many thanks in advance


Solution

  • console.log can take arbitrary number of arguments so you can put all data you need to log separating it by commas or concat same type values

     console.log("Titoli " , titval);
    
     console.log("Titoli " + JSON.stringify(titval));
    

    titval=[{"id":1}]
    
    console.log("Titoli " + titval);
    console.log("Titoli " , titval);
    console.log("Titoli " , JSON.stringify(titval));