我有一个数组和一个与数组匹配的计数器。
我需要的是具有以下属性的序列: 当计数器达到x6时,应将前5个项目设置为false。 当计数器达到x11时,应将前10个项目设置为false。 这样一来,只有5个项目一次被设置为true。
//in .ts for reference
//Counter, which is matched with the array - they are then saved:
this.counter+=1;
var xNum="x"+this.counter;
this.x[xNum] = true;
//Array of items to infinite
public x : any = ["x0", "x1", "x2", "x3", "x4", "x5", "x6",
"x7", "x8", "x9", "x10", "x11", "x12",
"x13", "x14", "x15", "x16", "x17", "x18"...]
答案 0 :(得分:0)
也许是这样的:
if(counter >= 5 && counter % 5 === 0){
for(let i = this.counter - 5; i < counter; i++){
const xNum = "x"+this.counter;
this.x[xNum] = false;
}
}