Array.prototype.keys()
Object.keys()可以在稀疏数组中筛选出数组中实际存在的key,keys()迭代器不会忽略属性不存在的key
1 const arr = ["a", , "c"]; 2 const sparseKeys = Object.keys(arr); 3 const denseKeys = [...arr.keys()]; 4 console.log(sparseKeys); // ['0', '2'] 5 console.log(denseKeys); // [0, 1, 2]