At the following code, I have the array of ["Saab", "Volvo", "BMW"]
.
<div>
<span id="my-element" class=" css-1yy09vp" data-font-weight="semibold"></span>
<script>
const cars = ["Saab", "Volvo", "BMW"];
const textElement = document.getElementById("text");
function carDisplayer() {
let i = 0;
return function(cars) {
let interval = setInterval(() => {
if (i < cars.length) {
textElement.textContent = cars[i];
i++;
} else {
clearInterval(interval);
i = 0;
}
}, 10000);
}
}
let displayCars = carDisplayer();
displayCars(cars);
</script>
</div>
I am interested in reading the content of the array from a text file instead of hardcoding. For example, if I have the following file;
Saab
Volvo
BMW
called "content.txt", how can I read the content and assign it as "cars" array?
Thanks,