TypedArray.prototype.copyWithin()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since 2016ë 9ì.
TypedArray ì¸ì¤í´ì¤ì copyWithin() ë©ìëë ì´ íìí ë°°ì´ì ì¼ë¶ë¥¼ ê°ì íìí ë°°ì´ì ë¤ë¥¸ ì¥ìì ìì ë³µì¬ë¥¼ ìííë©° ë°°ì´ì 길ì´ë¥¼ ìì íì§ ìê³ í´ë¹ ë°°ì´ì ë°íí©ëë¤. ì´ ë©ìëë Array.prototype.copyWithin()ì ê°ì ìê³ ë¦¬ì¦ì ê°ì§ëë¤.
ìëí´ ë³´ê¸°
const uint8 = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
// Insert position, start position, end position
uint8.copyWithin(3, 1, 3);
console.log(uint8);
// Expected output: Uint8Array [1, 2, 3, 2, 3, 6, 7, 8]
구문
copyWithin(target, start)
copyWithin(target, start, end)
매ê°ë³ì
target-
ìíì¤ë¥¼ ë³µì¬í 0 ê¸°ë° ì¸ë±ì¤ë¡, ì ìë¡ ë³í. ì´ë
startì ìë ììê° ë³µì¬ë ìì¹ì í´ë¹íë©°,startê³¼endì¬ì´ì 모ë ììë íì ì¸ë±ì¤ì ë³µì¬ë©ëë¤. start-
ìì ë³µì¬ë¥¼ ììí 0 ê¸°ë° ì¸ë±ì¤ë¡, ì ìë¡ ë³íë©ëë¤.
endOptional-
ìì ë³µì¬ë¥¼ ëë¼ 0 ê¸°ë° ì¸ë±ì¤ë¡, ì ìë¡ ë³íë©ëë¤.
copyWithin()ìend를 í¬í¨íì§ ìê³endì ê¹ì§ ë³µì¬í©ëë¤.copyWithin()ë ì¬ê¸°ê¹ì§ ë³µì¬íì§ë§end를 í¬í¨íì§ë ììµëë¤.
ë°í ê°
ìì ë íìí ë°°ì´
ì¤ëª
ë³´ë¤ ìì¸í ì¤ëª
ì Array.prototype.copyWithin()ì ì°¸ê³ íì기 ë°ëëë¤. ì´ ë©ìëë ë²ì© ë©ìëê° ìëë©° ì¤ì§ íìí ë°°ì´ ì¸ì¤í´ì¤ììë§ í¸ì¶í ì ììµëë¤.
ìì
>copyWithin() ì¬ì©í기
const buffer = new ArrayBuffer(8);
const uint8 = new Uint8Array(buffer);
uint8.set([1, 2, 3]);
console.log(uint8); // Uint8Array [ 1, 2, 3, 0, 0, 0, 0, 0 ]
uint8.copyWithin(3, 0, 3);
console.log(uint8); // Uint8Array [ 1, 2, 3, 1, 2, 3, 0, 0 ]
ëª ì¸ì
| Specification |
|---|
| ECMAScript® 2027 Language Specification > # sec-%typedarray%.prototype.copywithin > |