I want to iterate over an array in a synchronous manner
let arr= new Array([10,20,30]);
for(let i=0;i<arr.length;i++){
htmldata+=`<h1>${arr[i]}</h1><br/>`
}
console.log(htmldata)
What I get output is
<h1>10,20,30</h1><br/>
what I expect to store in htmldata is (in string format)
<h1>10</h1><br/><h1>20</h1><br/><h1>30</h1><br/>
Tried from other stackoverflow answers, which gave me a way only to get the indices correctly, but not the array values
var funcs = [];
htmldata=``
for (let i = 0; i < 3; i++) {
funcs[i] = function() {
console.log("My value: " + i,arr[i]);
htmldata+=`<h1>${arr[i]}</h1><br/>`
};
}
for(let i=0;i<3;i++) funcs[i]();
console.log(htmldata)
output:
My value: 0 [ 10, 20, 30 ]
My value: 1 undefined
My value: 2 undefined
<h1>10,20,30</h1><br/><h1>undefined</h1><br/><h1>undefined</h1><br
How to do this?
new Array([10,20,30]);to do?