๐sparse array
JS โฉ object โฉ built-in โฉ Array โฉ sparse array
array that has "holes" in it.
"holes" are (usually) treated as undefined.
loops and array methods treat "holes" in sparse arrays differently.
forEach๏ผignores "holes".
map ๏ผpreserves holes.
filter ๏ผignores holes.
Array(n) vs. Array(n).fill()
Array(3)
ๅชๆ่จญๅฎ้ฃๅ้ทๅบฆ
{length: 3}
๏ผไธฆไธๆ่จญๅฎใๆดๆธ็ดขๅผใๅฑฌๆงๅฆๆๅ
.map()
๏ผๅชๆๅพๅฐ็ฉบ้ฃๅ๏ผๅ ็บ.map()
ๆไฟ็ใๆดใใ
Array(3).fill()
ๆๅกซๅ ฅ
undefined
๏ผไธฆ่จญๅฎใๆดๆธ็ดขๅผใๅฑฌๆง๏ผ้ๆไฝฟ็จ.map()
ๅฐฑๆๆๅฏฆ้ๆๆใ
Last updated
Was this helpful?