function displayValues(inputValues) {
for (var counter = 0; counter < inputValues.length; counter++) {
setInterval(function() {
console.log('The item ' + counter + ' has value ' + inputValues[counter]) //Currently only logs length of array
}, 500)
}
}
var arrayOfElements = ['a', 'b', 'c', 'd'];
displayValues(arrayOfElements)
I wrapped the SetInterval in a separate function that currently displays index 0 and its corresponding value 'a', however, I am unable to capture the values for the rest of the items. Here is my revised code below. Am I on the right track?
function showValues(valuesArray) {
function getDisplay(){
return setInterval(function() {
console.log('The item ' + i + ' has value ' + values[i])
}, 500)
}
for (var i = 0; i < valuesArray.length; i++) {
return getDisplay()
}
}