Baseline Widely available
Array
ì¸ì¤í´ì¤ì fill()
ë©ìëë ë°°ì´ì ì¸ë±ì¤ ë²ì ë´ì ìë 모ë ìì를 ì ì ê°ì¼ë¡ ë³ê²½í©ëë¤. ê·¸ë¦¬ê³ ìì ë ë°°ì´ì ë°íí©ëë¤.
const array1 = [1, 2, 3, 4];
// Fill with 0 from position 2 until position 4
console.log(array1.fill(0, 2, 4));
// Expected output: Array [1, 2, 0, 0]
// Fill with 5 from position 1
console.log(array1.fill(5, 1));
// Expected output: Array [1, 5, 5, 5]
console.log(array1.fill(6));
// Expected output: Array [6, 6, 6, 6]
구문
fill(value)
fill(value, start)
fill(value, start, end)
매ê°ë³ì
value
ë°°ì´ì ì±ì¸ ê°ì
ëë¤. ë°°ì´ì 모ë ììë ì íí ì´ ê°ì´ ë ê²ì
ëë¤. value
ê° ê°ì²´ì¸ ê²½ì°, ë°°ì´ì ê° ì¬ë¡¯ì í´ë¹ ê°ì²´ë¥¼ 참조í©ëë¤.
start
Optional
ì±ì°ê¸°ë¥¼ ììí 0 ê¸°ë° ì¸ë±ì¤ë¡, ì ìë¡ ë³íë©ëë¤.
start < 0
ì¸ ê²½ì°, start + array.length
ê° ì¬ì©ë©ëë¤.start < -array.length
ëë start
ê° ìëµë ê²½ì°, 0
ì´ ì¬ì©ë©ëë¤.start >= array.length
ì´ë©´, ì무 ì¸ë±ì¤ë ì±ìì§ì§ ììµëë¤.end
Optional
ì±ì°ê¸°ë¥¼ ëë¼ 0 ê¸°ë° ì¸ë±ì¤ë¡, ì ìë¡ ë³íë©ëë¤. fill()
ì end
ê¹ì§ ì±ì°ë©°, end
ë í¬í¨íì§ ììµëë¤.
end < 0
ì¸ ê²½ì°, end + array.length
ê° ì¬ì©ë©ëë¤.end < -array.length
ì´ë©´, 0
ì´ ì¬ì©ë©ëë¤.end >= array.length
ì´ê±°ë end
ê° ìëµë ê²½ì°, array.length
ê° ì¬ì©ëì´ ëê¹ì§ 모ë ì¸ë±ì¤ê° ì±ìì§ëë¤.end
ê° ì ìë¡ ë³íë í, after
ë³´ë¤ ìì ìì¹íë©´, ì무 ì¸ë±ì¤ë ì±ìì§ì§ ììµëë¤.value
ë¡ ì±ìì§ ë³ê²½ë ë°°ì´ì
ëë¤.
fill()
ë©ìëë ë³ê²½ ë©ìëì
ëë¤. ì´ ë©ìëë this
ì lengthë ë³ê²½íì§ ìì§ë§, this
ì ë´ì©ì ë³ê²½í©ëë¤.
fill()
ë©ìëë í¬ì ë°°ì´ì ë¹ ì¬ë¡¯ë value
ë¡ ì±ìëë¤.
fill()
ë©ìëë ë²ì©ì
ëë¤. this
ê°ìë length
ìì±ë§ ìì ê²ì¼ë¡ ììí©ëë¤. 문ìì´ë ì ì¬ ë°°ì´ì´ì§ë§, 문ìì´ì ë¶ë³ì´ë¯ë¡ ì´ ë©ìë를 ì ì©í기ìë ì í©íì§ ììµëë¤.
ì°¸ê³ : ë¹ ë°°ì´(length = 0
)ì Array.prototype.fill()
ì ì¬ì©íë©´ ë°°ì´ì ìì í ë´ì©ì´ ìì¼ë¯ë¡ ë°°ì´ì´ ìì ëì§ ììµëë¤. ë°°ì´ì ì ì¸í ë Array.prototype.fill()
ì ì¬ì©íë ¤ë©´ ë°°ì´ì 길ì´ê° 0ì´ ìëì§ íì¸íì¸ì. ìì 를 참조íììì¤.
console.log([1, 2, 3].fill(4)); // [4, 4, 4]
console.log([1, 2, 3].fill(4, 1)); // [1, 4, 4]
console.log([1, 2, 3].fill(4, 1, 2)); // [1, 4, 3]
console.log([1, 2, 3].fill(4, 1, 1)); // [1, 2, 3]
console.log([1, 2, 3].fill(4, 3, 3)); // [1, 2, 3]
console.log([1, 2, 3].fill(4, -3, -2)); // [4, 2, 3]
console.log([1, 2, 3].fill(4, NaN, NaN)); // [1, 2, 3]
console.log([1, 2, 3].fill(4, 3, 5)); // [1, 2, 3]
console.log(Array(3).fill(4)); // [4, 4, 4]
// ë°°ì´ì ê° ì¬ë¡¯ì´ 참조íë ë¨ì¼ ê°ì²´
const arr = Array(3).fill({}); // [{}, {}, {}]
arr[0].hi = "hi"; // [{ hi: "hi" }, { hi: "hi" }, { hi: "hi" }]
fill()ì ì¬ì©íì¬ ì ì²´ 1 íë ¬ë¡ ë§ë¤ê¸°
ì´ ìì ë Octave ëë MATLABì ones()
í¨ìì ê°ì´ ì ì²´ 1 íë ¬ì ë§ëë ë°©ë²ì ë³´ì¬ì¤ëë¤.
const arr = new Array(3);
for (let i = 0; i < arr.length; i++) {
arr[i] = new Array(4).fill(1); // í¬ê¸°ê° 4ì´ê³ , 1ë¡ ì±ìì§ ë°°ì´ ìì±
}
arr[0][0] = 10;
console.log(arr[0][0]); // 10
console.log(arr[1][0]); // 1
console.log(arr[2][0]); // 1
fill()ì ì¬ì©íì¬ ë¹ ë°°ì´ ì±ì°ê¸°
ì´ ìì ë 모ë ìì를 í¹ì ê°ì¼ë¡ ì¤ì íì¬ ë°°ì´ì ì±ì°ë ë°©ë²ì ë³´ì¬ì¤ëë¤. end
매ê°ë³ìë ì§ì í íìê° ììµëë¤.
const tempGirls = Array(5).fill("girl", 0);
ì´ ë°°ì´ì ì²ìì ì¸ë±ì¤ê° í ë¹ëì§ ìì í¬ì ë°°ì´ì´ììµëë¤. ê·¸ëë fill()
ì ì¬ì í ì´ ë°°ì´ì ì±ì¸ ì ììµëë¤.
fill()
ë©ìëë this
ì length
ìì±ì ì½ê³ start
ë¶í° end
ê¹ì§ ê° ì ì í¤ ìì± ê°ì ì¤ì í©ëë¤.
const arrayLike = { length: 2 };
console.log(Array.prototype.fill.call(arrayLike, 1));
// { '0': 1, '1': 1, length: 2 }
ëª
ì¸ì ë¸ë¼ì°ì í¸íì± ê°ì´ 보기
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4