Javascript ArrayBuffer slice()

Introduction

The Javascript ArrayBuffer slice() method returns a sub ArrayBuffer.

arraybuffer.slice(begin[, end])
Parameter Optional Meaning
begin Required Zero-based byte index at which to begin slicing.
end Optional Byte index before which to end slicing.

If end is unspecified, uses the length of ArrayBuffer.

The slice() method copies up to, but not including, the byte indicated by the end parameter.

If either begin or end is negative, it refers to an index from the end of the array.

Copying an ArrayBuffer

const buf1 = new ArrayBuffer(8);
console.log(buf1);
const buf2 = buf1.slice(0);
console.log(buf2);



PreviousNext

Related