use setInterval to implement multiple countdown. The code is as follows:
//responseDatatimeLeft
var groupOn = responseData.groupOn
for (let i = 0; i < 2; iPP) {
var timeLeft = groupOn[i].timeLeft
setInterval(() => {
timeLeft--
console.log(timeLeft)
}, 1000)
// setInterval(function (timeLeft) {
// timeLeft--
// // console.log(timeLeft)
// }, 1000, timeLeft)
}
the effect I want is that setInterval prints two timeLeft, per second, for example, if the initial values of two timeLeft are 10 and 20 respectively, then print once per second, the value decreases, the first method prints the value of the second timeLeft, the second method prints two timeLeft, respectively, but the value decreases only once, how can I achieve the desired effect? It feels like a closure problem, but I still don"t know how to rewrite
.