sparse array
Last updated
Was this helpful?
Last updated
Was this helpful?
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(3)
ๅชๆ่จญๅฎ้ฃๅ้ทๅบฆ {length: 3}
๏ผไธฆไธๆ่จญๅฎใๆดๆธ็ดขๅผใๅฑฌๆง
ๅฆๆๅ .map()
๏ผๅชๆๅพๅฐ็ฉบ้ฃๅ๏ผๅ ็บ .map()
ๆไฟ็ใๆดใใ
Array(3).fill()
ๆๅกซๅ
ฅ undefined
๏ผไธฆ่จญๅฎใๆดๆธ็ดขๅผใๅฑฌๆง๏ผ้ๆไฝฟ็จ .map()
ๅฐฑๆๆๅฏฆ้ๆๆใ