How iterate in an array with objects

How iterate in an array with objects
0

#1

I’m struggling find a way to iterate in my array with objects. How iterate in this?
My array have 8 Usr objects.

I have try iterate with forEach method.

function show_data(){
Users.forEach(function(objs){
  alert("It WOrk 1!");
    if(objs.live == true){
      twitchContainer.innerHTML += "<li>"+objs.name+"<img src='"+objs.image+"'>" +"<p>"+ "ici"+"</p>"+"</li>";

       }else{
         alert("It WOrk 2!");
   }
  });
}
show_data();

#2

Can you explain what you mean by iterate your array with objects?


#4

I try iterate in the Users Array to get user by the “live” propreties.


#5

I looked at your Codepen and the Users array is empty, so the code inside the forEach callback function will not execute.


#6

Oh so its empty when my function try to iterate in it?
Its hard understand how callback for each step. :sweat_smile:


#7

Thank’s for your help btw! :slight_smile:


#8

Yes, the Users array is empty before the forEach line. Put a console.log in to confirm.