(() => {
const paraElement = document.querySelector('#animated-text');
const spanElement = paraElement.querySelector('span');
const wordsList = JSON.parse(spanElement.dataset.words);
let counter = 0;
setInterval(function(){
spanElement.innerHTML = wordsList[counter];
if (counter < wordsList.length - 1) counter = counter + 1;
else counter = 0;
}, Math.ceil(Math.random() * 5) * 1000);
})();
<style>
#animated-text span {
color: red;
}
</style>
<p id="animated-text">
Lorem ipsum, or lipsum as it is sometimes known,
<span data-words='["One", "Two", "Three"]'>Default
</span>
is dummy text used in laying out print, graphic or web designs.
</p>