no-sparse-arrays
禁止稀疏数组。
稀疏数组是包含空槽位的数组,这些空槽位稍后可能被视为 undefined
值或被数组方法跳过,这可能会导致意外行为
[1, , 2].join(); // => '1,,2'
[1, undefined, 2].join(); // => '1,,2'
[1, , 2].flatMap((item) => item); // => [1, 2]
[1, undefined, 2].flatMap((item) => item); // => [1, undefined, 2]
无效
const items = ["foo", , "bar"];
有效
const items = ["foo", "bar"];