I've written a for loop that grabs information in my variable object, and now I am trying to use setInterval function inside my loop that will loop through the data displaying 1 piece of data at a time, while looping through the order:
var i = 0;
var twitterData = {
tweet1 : [{
user: {
profile_image_url : "assets/avatar.png",
name : "@Hodor"
},
text : "Hodor Hodor Hodor Hodor Hodor Hodor Hodor..... Hodor"
}],
tweet2 : [{
user: {
profile_image_url : "assets/avatar.png",
name : "@johnsnow"
},
text : "Someone once said that I know nothing..."
}],
tweet3 : [{
user: {
profile_image_url : "assets/avatar.png",
name : "@drwho"
},
text : "Fantastic!"
}]
};
sqTweetData = getTweetData();
function getTweetData() {
return twitterData;
}
for (var k in sqTweetData) {
// Gives me object {tweet1: Array[1], tweet2: Array[1]. tweet3: Array[1]}
console.log("sqTweetData = ",sqTweetData);
for (var l = 0; l < sqTweetData[k].length; l++) {
var foo = sqTweetData[k][l]
// Loops sqTweetData and returns object {user: object, text: "hodor hodor hodor etc"}
console.log("foo = ", foo);
setInterval(function() {
// returns the last object for tweet3 and does NOT display tweet1, tweet2, tweet3 in that order over 3000ms
console.log(foo);
i++;
}, 3000);
}
}
The issue I am having is that once inside the setInterval function, it only displays the last data (i.e. tweet3) and loops that piece over and over again. It is not looping through the data and displaying it in order. Thoughts?