Skip to content

Commit 0fc76fe

Browse files
committed
edit array/hole
1 parent b346091 commit 0fc76fe

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

docs/array.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,19 @@ Array.from(['a',,'b'])
461461
new Array(3).fill('a') // ["a","a","a"]
462462
```
463463

464+
`for...of`循环也会遍历空位。
465+
466+
```javascript
467+
let arr = [, ,];
468+
for (let i of arr) {
469+
console.log(1);
470+
}
471+
// 1
472+
// 1
473+
```
474+
475+
上面代码中,数组`arr`有两个空位,`for...of`并没有忽略它们。如果改成`map`方法遍历,空位是会跳过的。
476+
464477
`entries()``keys()``values()``find()``findIndex()`会将空位处理成`undefined`
465478

466479
```javascript

0 commit comments

Comments
 (0)