JS.next

JavaScriptの最新実装情報を追うブログ

Array.prototype.copyWithinが実装された

概要

copyWithinは配列の一部の区間を任意の位置から貼り付ける破壊的メソッドである。


使い方

Array.prototype.copyWithin( target, start, end? )
startからendの直前までの要素をtargetの位置から貼り付ける。
例:

var ary = [ 0, 1, 2, 3, 4, 5 ]

ary.copyWithin( 2, 4 )
console.log(ary)  // [ 0, 1, 4, 5, 4, 5 ]
var ary = [ -6, -5, -4, -3, -2, -1 ]

ary.copyWithin( -3, -4, -2 )
console.log(ary)  // [ -6, -5, -4, -4, -3, -1 ]


実装されるバージョン

V8 4.4.29 4.5.73(デフォルト有効)