[,'a'].every(x => x==='a')
> True
返回True,尽管第一项是“未定义”,因此应该是False?
[,'a'].map(x => x)
> [undefined × 1, "a"]
最佳答案
内置数组方法会忽略 sparse arrays 上不存在的属性。 。第一项不是未定义
,索引0
中根本没有属性。你可以试试
[,'a'].every(x => x==='a')
> true
[undefined,'a'].every(x => x==='a')
> false
关于javascript - 奇怪的 ES6 Array.every 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42102061/