JSFiddle - React, Tailwind, and code Playground

HTML

<div id=i0>0</div>
<div id=i1>1</div>
<div id=i2>2</div>
<div id=i3>3</div>
<div id=i4>4</div>
<div>z=<input id=iz>

JavaScript

// Each second, I want to increment the input and remove one number from the list

// Solution 1:

/*
z=0;
for(i=0;i<=4;i++){
  setTimeout("i"+i+".remove();z++;iz.value=z", 1000*i)
}
*/


// Solution 2:

/*
z=0;
	for(i=0;i<=4;i++){
	(x=>{ setTimeout(_=>{document.getElementById(`i${x}`).remove();z++;iz.value=z;},1000*x); })(i);
}
*/


// Solution 3:
/*
z=0;
for(i=0;i<=4;i++){
  (function(i) {
    setTimeout(()=>{
      document.getElementById("i"+i).remove();
      z++;
      iz.value = z;
    },1000*i)
  })(i); 
}
*/

// Solution 4
/*
z=0;
for(let i=0;i<=4;i++){
	setTimeout(()=>{
  	document.getElementById("i"+i).remove();
    z++;
    iz.value = z;
  },1000*i)
}
*/