I made a variable and added new values with the push attribute but when the for-loop calls it one-by-one it only prints the last value(name) that is "Pranav". Can you help me to know how to fix it and print all the values one-by-one.
function tryme() {
var names = new Array();
names.push("Bhavesh", "Ajay", "Rahul", "Vinod", "Bobby", "Pranav");
var tryit = document.getElementById("tryit");
for (i = 0; i < names.length; i++) {
tryit.innerHTML = "The values are " + names[i] + " . <br>"
};
};
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…