这个 达雷。copyWithin() 是JavaScript中的一个内置函数,用于在同一typedArray中的指定位置复制typedArray的某些元素。
null
语法:
typedArray.copyWithin(target, start, end)
参数: 它接受下面指定的三个参数-
返回值: 复制过程完成后,它返回修改后的数组。
<script> // Constructing a new typedArray "A" // with some elements const A = new Uint8Array([ 5, 10, 15, 20, 25, 30, 35, 40 ]); // Calling copyWithin function to copy // element from index position 0 and // element from index 4 to 5 A.copyWithin(0, 4, 5); // Printing a new modified array document.write(A); </script> |
输出:
25,10,15,20,25,30,35,40
代码#2:
<script> // Constructing some new typedArrays // with some elements const A = new Uint8Array([ 5, 10, 15, 20, 25, 30, 35, 40 ]); const B = new Uint8Array([ 5, 10, 15, 20, 25, 30, 35, 40 ]); const C = new Uint8Array([ 5, 10, 15, 20, 25, 30, 35, 40 ]); const D = new Uint8Array([ 5, 10, 15, 20, 25, 30, 35, 40 ]); const E = new Uint8Array([ 5, 10, 15, 20, 25, 30, 35, 40 ]); // Calling copyWithin function with different // parameters a = A.copyWithin(0, 5); b = B.copyWithin(1, 4); c = C.copyWithin(0, 4, 5); d = D.copyWithin(2, 3, 5); e = E.copyWithin(0, 1, 4); // Printing new modified arrays document.write(a + "<br>" ); document.write(b + "<br>" ); document.write(c + "<br>" ); document.write(d + "<br>" ); document.write(e); </script> |
输出:
30,35,40,20,25,30,35,40 5,25,30,35,40,30,35,40 25,10,15,20,25,30,35,40 5,10,20,25,25,30,35,40 10,15,20,20,25,30,35,40
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END