var fruits = [1, 2, 3]; fruits.forEach(myFunction); function myFunction(item, index) { document.getElementById("demo").innerHTML += index + ":" + item + "<br>"; }