JavaScript 中的 TypedArray.copyWithin() 函数
htmljavascriptprogramming scripts更新于 2024/10/19 2:20:17
TypedArray 对象的 copyWithin() 函数会将此 TypedArray 的内容复制到其自身内。此方法接受三个数字,其中第一个数字表示应开始复制元素的数组索引,接下来的两个数字表示应从中复制(获取)数据的数组的起始和结束元素。
语法
其语法如下
obj.copyWithin(3, 1, 3);
示例
<html>
<head>
<title>JavaScript 示例</title>
</head>
<body>
<script type="text/javascript">
var int32View = new Int32Array([21, 64, 89, 65, 33, 66, 87, 55 ]);
document.write("类型化数组的内容:"+int32View);
int32View.copyWithin(5, 0, 5);
document.write("<br>");
document.write("复制后类型化数组的内容:"+int32View);
</script>
</body>
</html>
输出
类型化数组的内容:21,64,89,65,33,66,87,55 复制后类型化数组的内容:21,64,89,65,33,21,64,89
示例
不必将第三个参数传递给此函数(应从中复制数据的数组的末尾元素),它将复制到数组末尾。
<html>
<head>
<title>JavaScript 示例</title>
</head>
<body>
<script type="text/javascript">
var int32View = new Int32Array([21, 64, 89, 65, 33, 66, 87, 55 ]);
document.write("类型化数组的内容:"+int32View);
int32View.copyWithin(5, 0);
document.write("<br>");
document.write("复制后类型化数组的内容:"+int32View);
</script>
</body>
</html>
输出
类型化数组的内容:21,64,89,65,33,66,87,55 复制后类型化数组的内容:21,64,89,65,33,21,64,89
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

