JavaScript中的TypedArray.fill()函数
fill()TypedArray对象的功能用指定值(固定)替换数组的所有必需/期望元素。此函数接受三个数字,一个代表固定值,另外两个代表要替换的元素部分的开始和结束索引(结束值是可选的)。
语法
其语法如下
int32View.fill(464, 3);
示例
<html>
<head>
<title>JavaScript Array every Method</title>
</head>
<body>
<script type="text/javascript">
var int32View = new Int32Array([64, 89, 65,21, 14, 66, 87, 55]);
document.write("Contents of the typed array: "+int32View);
document.write("<br>");
result = int32View.fill(464, 3);
document.write("Contents of the typed array after fill: "+int32View);
</script>
</body>
</html>输出结果
Contents of the typed array: 64,89,65,21,14,66,87,55 Contents of the typed array after fill: 64,89,65,464,464,464,464,464