Help with Array


I need some help with the array of objectsfrom twitch tv ->
I can’t understand this behaviour. I assign the array to a variable called canales.
I’m trying to go over the array for extracting every channel (stream object). So I’m running this loop

  for (var i=0; i< data.length; i++){
    console.log(data[i]['stream'].name, i);
    var html = '';
    html += '<div class="col-xs-12 col-md-6 col-lg-4">';
    html += '<div class="canal" id="canal' + data[i]['stream'].name + '">';

The console is telling me that I’ve a string, the name is freecodecamp and it’s the first element(0). Correct. But, I don’t know why I’m getting also this error:
TypeError: data[i].stream is null[Learn More] index.html:161:21

Why I’m receiving a string and at the same it’s telling me that it’s null?

Can you post your code, preferably in a CodePen or some other online editor?

Here it is:

The next element after “freecodecamp” is null. “stream” property doesn’t contain any values there.

Yes, of course, but what I can’t understand, it’s why the loop is not continuing, I mean,

The first element name is freecodecamp.
The second is null.
The loop is not continuing, but should continue with the third element that is
The fourth is null
The fifth is also null.

That’s because of an error due to the elements being null - “TypeError: data[i].stream is null”.
You need to check if the value’s null before doing things to prevent such behavior.

var test1;
if (test1) // false
console.log(“not null!!”);

var test2 = 123;
if (test2) // true
    console.log("not null!!");