[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray [Back]  [Original]

TypedArray.prototype.subarray() - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

TypedArray.prototype.subarray()

Baseline

20157

subarray() TypedArray ArrayBuffer

const uint8 = new Uint8Array([10, 20, 30, 40, 50]);

console.log(uint8.subarray(1, 3));
// : Uint8Array [20, 30]

console.log(uint8.subarray(1));
// : Uint8Array [20, 30, 40, 50]

js
subarray()
subarray(begin)
subarray(begin, end)

begin

end

begin

TypedArray

begin end begin end

subarray()

js
const buffer = new ArrayBuffer(8);
const uint8 = new Uint8Array(buffer);
uint8.set([1, 2, 3]);

console.log(uint8); // Uint8Array [ 1, 2, 3, 0, 0, 0, 0, 0 ]

const sub = uint8.subarray(0, 4);

console.log(sub); // Uint8Array [ 1, 2, 3, 0 ]

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


Web Proxy Viewer  |  New URL  |  Original Page