Adding loop to Typewriter Code

Hi,

I have this code that works fine and show’s the first text, then backspace then the secone and so on…

What i need is that after the 3rd text it should again start from the 1st. i,e add a loop.

let index = 0;
let textLines = [
“First line of text”,
“Second line of text”,
“Third line of text”
];

let backspacing = false;
let backspaceIndex = 0;

let typeWriter = setInterval(function() {
if (backspacing) {
if (backspaceIndex > 0) {
$w(“#myText”).text = textLines[index].substring(0, backspaceIndex-1);
backspaceIndex–;
} else {
backspacing = false;
index++;
if (index >= textLines.length) {
clearInterval(typeWriter);
}
}
} else {
if (backspaceIndex < textLines[index].length) {
$w(“#myText”).text = textLines[index].substring(0, backspaceIndex+1);
backspaceIndex++;
} else {
backspacing = true;
}
}
}, 100);



appreciate your help on this.