Baseline Widely available
Array
ì¸ì¤í´ì¤ì copyWithin()
ë©ìëë ë°°ì´ì ì¼ë¶ë¥¼ ê°ì ë°°ì´ì ë¤ë¥¸ ìì¹ë¡ ìê² ë³µì¬íë©°, ë°°ì´ì 길ì´ë¥¼ ìì íì§ ìê³ í´ë¹ ë°°ì´ì ë°íí©ëë¤.
const array1 = ["a", "b", "c", "d", "e"];
// Copy to index 0 the element at index 3
console.log(array1.copyWithin(0, 3, 4));
// Expected output: Array ["d", "b", "c", "d", "e"]
// Copy to index 1 all elements from index 3 to the end
console.log(array1.copyWithin(1, 3));
// Expected output: Array ["d", "d", "e", "d", "e"]
구문
copyWithin(target, start)
copyWithin(target, start, end)
매ê°ë³ì
target
ìíì¤ë¥¼ ë³µì¬í 0 ê¸°ë° ì¸ë±ì¤ë¡, ì ìë¡ ë³íë©ëë¤. ì´ë start
ì ìë ììê° ë³µì¬ë ìì¹ì í´ë¹íë©°, start
ê³¼ end
ì¬ì´ì 모ë ììë íì ì¸ë±ì¤ì ë³µì¬ë©ëë¤.
-array.length <= target < 0
ì´ë¼ë©´, target + array.length
ì´ ì¬ì©ë©ëë¤.target < -array.length
ì´ë©´, 0
ì´ ì¬ì©ë©ëë¤.target >= array.length
ì´ë©´, ì무ê²ë ë³µì¬ëì§ ììµëë¤.target
ì´ start
ë³´ë¤ ë¤ì ìì¹íë©´, array.length
ì ëë¶ë¶ê¹ì§ë§ ë³µì¬ê° ìíë©ëë¤(ì¦, copyWithin()
ì ë°°ì´ì íì¥íì§ ììµëë¤).start
ìì ë³µì¬ë¥¼ ììí 0 ê¸°ë° ì¸ë±ì¤ë¡, ì ìë¡ ë³íë©ëë¤.
-array.length <= start < 0
ì´ë¼ë©´, target + array.length
ì´ ì¬ì©ë©ëë¤.target < -array.length
ì´ë©´, 0
ì´ ì¬ì©ë©ëë¤.target >= array.length
ì´ë©´, ì무ê²ë ë³µì¬ëì§ ììµëë¤.end
Optional
ìì ë³µì¬ë¥¼ ëë¼ 0 ê¸°ë° ì¸ë±ì¤ë¡, ì ìë¡ ë³íë©ëë¤. copyWithin()
ì end
를 í¬í¨íì§ ìê³ end
ì ê¹ì§ ë³µì¬í©ëë¤.
-array.length <= end < 0
ì´ë¼ë©´, target + array.length
ì´ ì¬ì©ë©ëë¤.target < -array.length
ì´ë©´, 0
ì´ ì¬ì©ë©ëë¤.end >= array.length
ì´ê±°ë end
ê° ìëµëë©´, array.length
ê° ì¬ì©ë©ëë¤. ì´ë ëê¹ì§ 모ë ìì를 ë³µì¬íë ê²ì´ ë©ëë¤.end
ê° start
ê° ììíë ìì¹ë ê·¸ ìì ìì¹ë¥¼ ììíë ê²½ì° ì무ê²ë ë³µì¬ëì§ ììµëë¤.ë³ê²½ë ë°°ì´ì ëë¤.
ì¤ëªcopyWithin()
ë©ìëë Cì C++ì memmove
ì²ë¼ ìëíë©°, Array
ì ë°ì´í°ë¥¼ ì´ëíë ê³ ì±ë¥ ë©ìëì
ëë¤. ì´ë í¹í ê°ì ì´ë¦ì ë©ìë를 ê°ì§ TypedArray
ììë ì ì©ë©ëë¤. ìíì¤ë íëì ìì
ì¼ë¡ ë³µì¬ì ë¶ì¬ë£ê¸°ê° ì´ë£¨ì´ì§ëë¤. ë³µì¬ ë¶ì¬ë£ê¸° ììì´ ê²¹ì¹ëë¼ë ë¶ì¬ë£ì ìíì¤ë ë³µì¬ë ê°ì ê°ìµëë¤.
undefined
를 ì ìë¡ ë³ííë©´ 0
ì´ ëë¯ë¡, start
매ê°ë³ì를 ìëµíë©´ 0
ì ì ë¬íì¬ ì ì²´ ë°°ì´ì target ìì¹ë¡ ë³µì¬íë ê²ê³¼ ëì¼í í¨ê³¼ê° ììµëë¤. ì´ë ì¤ë¥¸ìª½ ê²½ê³ê° ìë¦¬ê³ ì¼ìª½ ê²½ê³ê° ë³µì ëë ì¤ë¥¸ìª½ ìíí¸ì ê°ìµëë¤. ì´ ëìì ì½ë를 ì½ë ì¬ëìê² í¼ëì ì¤ ì ìì¼ë¯ë¡ ëª
ìì ì¼ë¡ 0
ì start
ë¡ ì ë¬íëê²ì´ ì¢ìµëë¤.
console.log([1, 2, 3, 4, 5].copyWithin(2));
// [1, 2, 1, 2, 3]; 모ë ìì를 ì¤ë¥¸ìª½ì¼ë¡ 2칸 ì´ëí©ëë¤.
copyWithin()
ë©ìëë ë³ê²½ ë©ìëì
ëë¤. this
ì 길ì´ë¥¼ ë³ê²½íì§ ìì§ë§, íìí ê²½ì° this
ì ë´ì©ì ë³ê²½íê³ , ì ìì±ì ë§ë¤ê±°ë 기존 ìì±ì ìì í©ëë¤.
copyWithin()
ë©ìëë ë¹ ì¬ë¡¯ì ë³´ì¡´í©ëë¤. ë³µì¬í ììì´ í¬ìì¸ ê²½ì°, ë¹ ì¬ë¡¯ì í´ë¹ ì ì¸ë±ì¤ì ìë í목ì ìì ëê³ ë¹ ì¬ë¡¯ì´ ë©ëë¤.
copyWithin()
ë©ìëë ë²ì©ì
ëë¤. this
ê°ì length
ìì±ê³¼ ì ì í¤ ìì± ë§ì 기ëí©ëë¤. 문ìì´ë ì ì¬ ë°°ì´ì´ì§ë§, 문ìì´ì ë¶ë³ì´ë¯ë¡ ì´ ë©ìë를 ì ì©í기ìë ì í©íì§ ììµëë¤.
console.log([1, 2, 3, 4, 5].copyWithin(0, 3));
// [4, 5, 3, 4, 5]
console.log([1, 2, 3, 4, 5].copyWithin(0, 3, 4));
// [4, 2, 3, 4, 5]
console.log([1, 2, 3, 4, 5].copyWithin(-2, -3, -1));
// [1, 2, 3, 3, 4]
í¬ì ë°°ì´ìì copyWithin() ì¬ì©í기
copyWithin()
ì ë¹ ì¬ë¡¯ì ì íí©ëë¤.
console.log([1, , 3].copyWithin(2, 1, 2)); // [1, empty, empty]
copyWithin()ì ë°°ì´ì´ ìë ê°ì²´ì ì ì©í기
copyWithin()
ë©ìëë this
ì length
ìì±ì ì½ì ë¤ì ê´ë ¨ë ì ì ì¸ë±ì¤ë¥¼ ë³ê²½í©ëë¤.
const arrayLike = {
length: 5,
3: 1,
};
console.log(Array.prototype.copyWithin.call(arrayLike, 0, 3));
// { '0': 1, '3': 1, length: 5 }
console.log(Array.prototype.copyWithin.call(arrayLike, 3, 1));
// { '0': 1, length: 5 }
// ë³µì¬ë ìì¤ê° ë¹ ì¬ë¡¯ì´ë¯ë¡ '3' ìì±ì´ ìì ë©ëë¤.
ëª
ì¸ì ë¸ë¼ì°ì í¸íì± ê°ì´ 보기
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