I am trying to work with data sent from a server using the following code where msg is the incoming data that holds two arrays:
console.log(msg);
for (var i = 0; i <= msg.cues.length; i++) {
$("#cues").append("<div class=\"cue-item\" cueval=\"cue-" + i + "\"><h4>"+msg.cues[i].name+"</h4>"+msg.cues[i].description+"</div>");
}
This code adds the required elements to the page and everything seems to be fine from the browser window, but in the console I get the below error that blocks all other code from running:
{…}
channels: Array [ 0, 0, 0, … ]
cues: […]
0: Object { name: "Cue 1", description: "This is a test cue" }
TypeError: msg.cues[i] is undefined
Any idea why this is happening and how I can solve this issue?
forstatement is wrong, it should befor (var i = 0; i < msg.cues.length; i++)