[Solved] How to loop in javascript?


As @Robby Cornelissen has said, you are wrapping your array in another array, which is unnecessary and breaking your code. Your for loop only iterates over a single element in the outer array.

Also, it is strange for an API response to have a JSON string embedded as a string value within a JSON’s property. You should post how you are retrieving the data.

response={data:[{games:`[{"gamename":"game 1","gamelink":"link 1","image_link":"image 1","startfrom":"1"},{"gamename":"game 2","gamelink":"link 2","image_link":"imgae 2","startfrom":"2"}]`}]}

    var json = response.data[0].games;
    console.log(json);
    
    var array = JSON.parse(json);
    console.log(array);
    
    for (var i = 0; i < array.length; i++) {
     console.log('gamename : ' +array[i].gamename+ " - game link: " +array[i].image_link);
    
    }

solved How to loop in javascript?