1
0
mirror of https://github.com/ruanyf/es6tutorial.git synced 2025-05-24 18:32:22 +00:00

edit array/hole

This commit is contained in:
ruanyf 2015-11-12 22:52:27 +08:00
parent b3460911dc
commit 0fc76fec74

View File

@ -461,6 +461,19 @@ Array.from(['a',,'b'])
new Array(3).fill('a') // ["a","a","a"]
```
`for...of`循环也会遍历空位。
```javascript
let arr = [, ,];
for (let i of arr) {
console.log(1);
}
// 1
// 1
```
上面代码中,数组`arr`有两个空位,`for...of`并没有忽略它们。如果改成`map`方法遍历,空位是会跳过的。
`entries()``keys()``values()``find()``findIndex()`会将空位处理成`undefined`
```javascript