TypedArray.prototype.fill()
TypedArray
实例的 fill()
方法将类型化数组中索引范围内的所有元素更改为静态值。它返回修改后的类型化数组。该方法与 Array.prototype.fill()
的算法相同。
¥The fill()
method of TypedArray
instances changes all elements within a range of indices in a typed array to a static value. It returns the modified typed array. This method has the same algorithm as Array.prototype.fill()
.
Try it
语法
参数
返回值
描述
¥Description
详细信息请参见 Array.prototype.fill()
。此方法不是通用的,只能在类型化数组实例上调用。
¥See Array.prototype.fill()
for more details. This method is not generic and can only be called on typed array instances.
示例
使用 fill()
¥Using fill()
js
new Uint8Array([1, 2, 3]).fill(4); // Uint8Array [4, 4, 4]
new Uint8Array([1, 2, 3]).fill(4, 1); // Uint8Array [1, 4, 4]
new Uint8Array([1, 2, 3]).fill(4, 1, 2); // Uint8Array [1, 4, 3]
new Uint8Array([1, 2, 3]).fill(4, 1, 1); // Uint8Array [1, 2, 3]
new Uint8Array([1, 2, 3]).fill(4, -3, -2); // Uint8Array [4, 2, 3]
规范
Specification |
---|
ECMAScript Language Specification # sec-%typedarray%.prototype.fill |
浏览器兼容性
BCD tables only load in the browser