Js中数组空位问题
console.log([,]); // (3) [empty × 3]
console.log(new Array(3)); // (3) [empty × 3]
console.log([undefined,undefined,undefined]); // (3) [undefined,undefined]
console.log(0 in [undefined,undefined]); // true
console.log(0 in [,]); // false // in 是检查索引 此处表示 0 位置是没有值的
// forEach 忽略空位
[1,2].forEach(v => console.log(v)); // 1 2
// for in 忽略空位
for(let key in [1,2]){ console.log(key); } // 0 2
// filter 忽略空位
console.log([1,2].filter(v => true)); // [1,2]
// every 忽略空位
console.log([1,1].every(v => v === 1)); // true
// some 忽略空位
console.log([1,1].some(v => v !== 1)); // false
// map 遍历时忽略空位 新数组保留空位
console.log([1,1].map(v => 11)); // (3) [11,empty,11]
// join 将空位与undefined以及null视为空字符串
console.log([1,1,null,undefined].join("|")); // 1||1||
// toString 将空位与undefined以及null视为空字符串
console.log([1,undefined].toString()); // 1,
// Array.form 将空位转为undefined
console.log(Array.from([1,2])); // (3) [1,2]
// ... 将空位转为undefined
console.log([...[1,2]]); // (3) [1,2]
// copyWithin 将空位一并拷贝
console.log([1,2].copyWithin()); // (3) [1,2]
// for of 遍历空位并将值作为undefined
for(let key of [1,2]){ console.log(key); } // 1 undefined 2
// includes 将空位处理成undefined
console.log([,].includes(undefined)); // true
// entries 将空位处理成undefined
console.log([...[1,2].entries()]); // [[0,1],[1,undefined],[2,2]]
// keys 会取出空位的索引
console.log([...[1,2].keys()]); // [0,2]
// values 将空位处理成undefined
console.log([...[1,2].values()]); // [1,2]
// find 将空位处理成undefined
console.log([,1].find(v => true)); // undefined
// find 将空位处理成undefined
console.log([,1].findIndex(v => true)); // 0
https://github.com/WindrunnerMax/EveryDay
https://www.zhihu.com/question/60919509
https://juejin.im/post/6844903917738786829
https://segmentfault.com/a/1190000004680060
https://xmoyking.github.io/2016/12/17/js-framework2/
https://juejin.im/post/6844904047934373896#heading-12
https://blog.csdn.net/qq_30100043/article/details/53308524
https://blog.csdn.net/weixin_43342105/article/details/108638001