Iterate through json array using javascript

Javascript Array:

var myArray = {"artists":[{
            "a1":"Adam Sandler",
            "a2":"Adam Lambert",
            "a3":"Avril Levine",
            "a4":"Backstreet Boys",
            "a6":"Black Eye Peas",
            "a7":"Cool and the Gang",
            "a9":"Charlie Manson"

            "s1":"Grow Old With You",
            "s2":"Whatdaya Want From Me",
            "s3":"Yea yea",
            "s4":"Quit Playing Games With My Heart",
            "s5":"No Digity",
            "s6":"Meet Me Half way",
            "s7":"Doo wa ditty",
            "s8":"Fight for your honor",
            "s9":"Charlies Song"
            "g4":"R & B",
            "g5":"R & B",
            "g8":"Soft Rock",

Javascript code to loop only songs:

$.each(myArray.songs, function (i, ob) {
    $.each(ob, function (ind, obj) {
        $('#result').append("key:" + ind + " value:" + obj+"<br/>")

Html Div To Paste The output:

<div id="result">


key:s1 value:Grow Old With You
key:s2 value:Whatdaya Want From Me
key:s3 value:Yea yea
key:s4 value:Quit Playing Games With My Heart
key:s5 value:No Digity
key:s6 value:Meet Me Half way
key:s7 value:Doo wa ditty
key:s8 value:Fight for your honor
key:s9 value:Charlies Song 


Post a Comment

Online Casino