I am new to JavaScript.
What I want to do is print the elements of an array one by one on the same location, but after a specific time interval.
Here it prints only the last element.
<!DOCTYPE html>
<html>
<head>
<title>sample</title>
</head>
<body>
<p id="test"></p>
<script>
const words = [ "Word1" , "word2" , "word3" , "word4" ];
for (let i = 0; i < words.length; i++ ) {
console.log(words[i]);
setTimeout(function(){ document.getElementById('test').innerHTML = words[i]; }, 2000);
}
</script>
</body>
</html>