var arr = [ {"id":"10", "class": "child-of-9"}, {"id":"11", "class": "child-of-10"}];
    
for (var i = 0; i < arr.length; i++){
  document.write("<br><br>array index: " + i);
  var obj = arr[i];
  for (var key in obj){
    var value = obj[key];
    document.write("<br> - " + key + ": " + value);
  }
}

note: the for-in method is cool for simple objects. Not very smart to use with DOM object.

Answer from Your Friend Ken on Stack Overflow
🌐
Reddit
reddit.com › r/learnjavascript › how to loop through an array with json objects
r/learnjavascript on Reddit: How to loop through an array with JSON objects
December 30, 2022 -

Hi all,

Im really struggling with this problem today. So basically, I have an array in the format

arr = [{title: " some title", id: "some id"}, {title: " some title2", id: "some id2"}] and all im trying to do is loop through each item in the array and get the value of the ids.

Here is what ive tried:

for( var i = 0; i< arr.length; i++){

console.log(arr[i].id)

}

It keeps showing up as undefined, please can anyone assist me? I would like the result to be "some id"

Discussions

How to loop through each item of a json array?
I have a .json file that I am using to have data for each level. I have an array in the .json file that i need to loop through the data for a level to generate it, except when i use this: for(i in leveldata){ loadLevel(levelData[i]); } it gives an error saying You can't iterate on a Dynamic ... More on community.haxe.org
🌐 community.haxe.org
5
0
April 27, 2021
Possible to iterate through a JSON object and return values of each property?
Hey all, I’m trying to add a shopping list to my Recipe box project as an extra personalization, and when researching on how to do this, one camper recommended that in order for me to render my Shopping list in a different target, I make a stateful component, and update the state as I add ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
0
July 3, 2017
How to iterate/loop a JSON of objects?
Describe the problem/error/question Below I have pasted an HTTP node that gets a JSON from a website. What I want to do is process it like a list with a Loop node, iterating each object in the list. The list contains objects, which are the names of softwares I am tracking, and each object contains ... More on community.n8n.io
🌐 community.n8n.io
1
0
September 8, 2025
javascript - Iterate through JSON-Object Array - Stack Overflow
I parsed a XML file and retrieved the following JSON-object. The issue is that there are dashes in the json, which causes problems iterating through the object. I can not get rid off them unfortuna... More on stackoverflow.com
🌐 stackoverflow.com
March 27, 2017
🌐
SitePoint
sitepoint.com › blog › javascript › how to loop through a json response in javascript
How to Loop Through a JSON Response in JavaScript — SitePoint
February 15, 2024 - Here’s an example: let obj = ... into a JSON string. Handling JSON arrays in JavaScript can be done using array methods like forEach(), map(), filter(), etc....
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-iterate-json-object-in-javascript
How to Iterate JSON Object in JavaScript? - GeeksforGeeks
July 23, 2025 - The forEach method can then be applied to iterate through the array of entries. Inside the loop, both the key and value of each property can be accessed directly. ... const obj = { "company": 'GeeksforGeeks', "contact": '+91-9876543210', "city": ...
🌐
W3Schools
w3schools.com › js › js_json_arrays.asp
JSON Arrays
JS Arrays JS Array Methods JS Array Search JS Array Sort JS Array Iterations JS Array Reference JS Array Const
🌐
Medium
medium.com › @beckerjustin3537 › javascript-using-array-iteration-methods-on-a-json-file-with-nested-objects-2c66b25df91e
JavaScript: Using Array Iteration Methods on a JSON file with Nested Objects | by Justin Becker | Medium
May 16, 2023 - The first project I created as a student at Flatiron School I faced the challenge of working with a JSON file that contained a nested object. Luckly JavaScript comes equipped with methods that can iterate through arrays. In this blog post I will go over five of the array iteration methods that I have used recently in my project and also during my phase-1 of Flatiron.
Find elsewhere
🌐
Microverse
microverse.org › home › blog › how to loop through the array of json objects in javascript
How to Loop Through the Array of JSON Objects in JavaScript
September 29, 2022 - In this example, we are looping within the array. {% code-block language="js" %} for (i=0; i<books.length; i++){ document.write( books.title + "<br />" ); } ‍{% code-block-end %} Once, I run this, all of the titles in my database would be displayed as shown below. Now, that should help you better understand how to loop through JSON.
🌐
ServiceNow Community
servicenow.com › community › developer-forum › accessing-iterating-json-response-array › m-p › 2924680
Solved: Accessing / Iterating JSON response array - ServiceNow Community
May 11, 2024 - function getResponse(response) { // First, parse the JSON string into an array of objects var response = JSON.parse(response); console.log(response); // This will now show the actual array of objects // Looping through the array using a for loop for (var i = 0; i < response.length; i++) { console.log(response[i].name); // Correctly accessing each name property } // Using a for-in loop to iterate over array indices (not typically recommended for arrays) for (var index in response) { if (response.hasOwnProperty(index)) { console.log(response[index].name); } } // Using a for loop to display alerts (if needed) for (var loop = 0; loop < response.length; loop++) { alert(response[loop].sysID); } }
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Possible to iterate through a JSON object and return values of each property? - JavaScript - The freeCodeCamp Forum
July 3, 2017 - Hey all, I’m trying to add a shopping list to my Recipe box project as an extra personalization, and when researching on how to do this, one camper recommended that in order for me to render my Shopping list in a differ…
🌐
Pluralsight
pluralsight.com › tech insights & how-to guides › tech guides & tutorials
Iterate Through a JSON Response in JSX Render for React | Pluralsight
September 25, 2020 - The map() method is the most commonly used function to iterate over an array of data in JSX. You can attach the map() method to the array and pass a callback function that gets called for each iteration.
🌐
CopyProgramming
copyprogramming.com › howto › nodejs-loop-through-json-array
Traversing a JSON Array in Node.js - Javascript
May 28, 2023 - Query: I have been assigned a task to traverse a complex JSON file containing a JSON array. Solution 2: The iteration is performed on the object properties in a random sequence.
🌐
Mirth Community
forums.mirthproject.io › home › mirth connect › support
Loop through JSON - Mirth Community
June 25, 2020 - In your example JSON object, regex for the "messages" name and, once you have found that, regex for the first child element ("AKA::AKA_Fname"), then grab all items within that set, parse and place them where they need to be, then regex for the next set. It takes a medium amount of thought, but may work. I also found a set of javascript functions at https://github.com/douglascrockford/JSON-js that appear to be pretty heavy duty, but do contain a couple of get functions for elements.
🌐
YouTube
youtube.com › watch
Nested JSON Objects | How to Iterate over the JSON Object and its Children Objects in Javascript - YouTube
Code : animals.json{ "Animals":{ "cat": { "humanFriendly": [ "Yes" ] }, "tiger": { "h...
Published   December 20, 2021
Top answer
1 of 4
1

Problem is with imgsrc = $imgUrl = $imgUrl + a;

Here is the working snippet

var photos = [{"photo1":"myimage1.jpg",
           "photo2":"myimg2.jpg",
           "photo3":"myimg3.jpg",
           "photo4":"myimg4.jpg"}];

            showPhotoOnLoad(photos,"imageurl");

           function showPhotoOnLoad(photos,$imgUrl){
           var $photoData = photos; 
           var photoLength =     Object.keys($photoData[0]).length;
           var i, key;  
           var $containerWidth = 110;
           //alert(photoLength);
           if(photoLength >0){
               $(".mycarousel-container").show();
                 for (i in $photoData) {
                for (key in $photoData[i]) {
                  a = $photoData[i][key];
                imgsrc = "a="+a; 
                var div = $("<div class='mycarousel' style='left:20px'></div>");
                var imgPreview = "<img  class='myimg' src="+imgsrc+">";
                div = div.append(imgPreview);
                $(".carouser-inner").append(div);
console.log(imgsrc);
               // left = left+$containerWidth;

                }               
              }
           }                              
           //console.log($imgUrl);            
       }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

2 of 4
0

I am not sure what this line is doing. imgsrc = $imgUrl = $imgUrl + a; you can simply loop over your data like this given your array will have only one object. If it has more you need a for loop wrapping the current loop to get all the objects.

photos = [{"photo1":"myimage1.jpg",
           "photo2":"myimg2.jpg",
           "photo3":"myimg3.jpg",
           "photo4":"myimg4.jpg",}];

       function showPhotoOnLoad(photos,$imgUrl){
       var $photoData = photos[0]; 

       var $containerWidth = 110;
       //alert(photoLength);
       if($photoData.length >0){
           $(".mycarousel-container").show();
            for (var i in $photoData){

            imgsrc = $photoData[i];
            var div = $("<div class='mycarousel' style='left:"+left+"px'></div>");
            var imgPreview = "<img  class='myimg' src="+imgsrc+">";
            div = div.append(imgPreview);
            $(".carouser-inner").append(div);

            left = left+$containerWidth;

            }               
          }
       }                              
       //console.log($imgUrl);            
   }
🌐
Code Maze
code-maze.com › home › how to iterate over json objects in c#
How to Iterate Over JSON Objects in C# - Code Maze
January 9, 2023 - Then, we loop over the list assigning values to the properties of the JsonIteration class. Is this material useful to you? Consider subscribing and get ASP.NET Core Web API Best Practices eBook for FREE! System.Text.Json also enables us to deserialize and iterate over JSON objects.