我的目标是将 actual 推undefined送到一个数组,类似于new Array(). 现在,如果你使用array.push(undefined)它并用array.forEach(element => count++)它来计数,它仍然被算作元素。
function test() {
let object = [5,,,5,"hoomba"]
object.push(undefined)
let maxRetries = 0;
object.forEach(element => maxRetries++);
console.log(object);
console.log(maxRetries);
}
test();
预期结果:
console.log(object) // [5, undefined, undefined, 5, "hoomba", undefined]
console.log(maxRetries) // 3
实际结果:
console.log(object) // [5, undefined, undefined, 5, "hoomba", undefined]
console.log(maxRetries) // 4
一只斗牛犬
慕后森
相关分类