如下代码,每隔200ms会打印出一组数据,希望能通过一个【停止按钮】来终止打印应该怎么实现?
let str = '12345'
let arr = ['1', '2', '3', '4', '5']
let arr1 = ['a', 'b', 'c', 'd', 'e']
arr.map((item, index1) => {
return arr1.map((i, index2) => {
setTimeout(() => {
console.log(str.replace(item, i))
}, (index1 * arr1.length + index2) * 1000)
})
})
在前面加个 变量保存 setTimeout 返回值就好了.