[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill [Back]  [Original]

TypedArray.prototype.fill() - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

TypedArray.prototype.fill()

20169

fill() Array.prototype.fill() TypedArray

js
fill(value)
fill(value, start)
fill(value, start, end)

value

start

0

end

this.length

[start, end)

fill valuestart endstart end 0 this.length

start length+start length end length+end

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]

TypedArray Array.prototype.fill()

js
// https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.fill
if (!Uint8Array.prototype.fill) {
  Uint8Array.prototype.fill = Array.prototype.fill;
}

ECMAScript 2027 LanguageSpecification
# sec-%typedarray%.prototype.fill


Web Proxy Viewer  |  New URL  |  Original Page