Search code examples
objectnotation

Can't get value from object key using .notation or bracket notation


for(j=0;j<twitchUserArray.length;j++)
        {
          displayALL(twitchUserArray[j]);
        }

    function displayALL(person){
      console.log("Inside displayALL");
      console.log(person);
      console.log(person.logo);

     }

Array[9]

0: Object

game: ""
logo: "http: //static-cdn.jtvnw.net/jtv_user_pictures/freecodecamp-profile_image-f1b681380c0b0380-300x300 .png"
name: "freecodecamp"
status: null
twitchfeed: "http: //www.twitch.tv/freecodecamp"
__proto__: Object

1: Object

game: ""
logo: "http: //static-cdn.jtvnw.net/jtv_user_pictures/storbeck-profile_image-7ab13c2f781b601d-300x300 .jpeg"
name: "storbeck"
status: null
twitchfeed: "http: //www.twitch.tv/storbeck"
__proto__: Object

2: Object

game: ""
logo: null
name: "terakilobyte"
status: null
twitchfeed: "http: //www.twitch.tv/terakilobyte"
__proto__: Object

Can anyone tell me the right syntax to get the values of a key when inside my displayALL function. Each index in that for loop is an object. Console.log(person) shows me the object with all the keys and values when troubleshooting in chrome but I've tried . notation and bracket notation and cannot get anything but undefined


Solution

  • Maybe you should look to see what a person is using typeof in displayALL

       for(j=0;j<twitchUserArray.length;j++)
        {
          displayALL(twitchUserArray[j]);
        }
    
        function displayALL(person){
          console.log("Inside displayALL");
          console.log(person);
          console.log(typeof person);
     }