The slice()
method of ArrayBuffer instances returns a new ArrayBuffer
whose contents are a copy of this ArrayBuffer
's bytes from
begin
, inclusive, up to end
, exclusive.
Syntax
slice()
slice(start)
slice(start, end)
Parameters
start
- : Zero-based index at which to start extraction, converted to an integer.
- Negative index counts back from the end of the buffer — if
start < 0
,start + buffer.length
is used. - If
start < -buffer.length
orstart
is omitted,0
is used. - If
start >= buffer.length
, nothing is extracted.
- Negative index counts back from the end of the buffer — if
- : Zero-based index at which to start extraction, converted to an integer.
end
- : Zero-based index at which to end extraction, converted to an integer.
slice()
extracts up to but not includingend
.- Negative index counts back from the end of the buffer — if
end < 0
,end + buffer.length
is used. - If
end < -buffer.length
,0
is used. - If
end >= buffer.length
orend
is omitted,buffer.length
is used, causing all elements until the end to be extracted. - If
end
is positioned before or atstart
after normalization, nothing is extracted.
- Negative index counts back from the end of the buffer — if
- : Zero-based index at which to end extraction, converted to an integer.
Return value
A new ArrayBuffer object.
Examples
Copying an ArrayBuffer
const buf1 = new ArrayBuffer(8);
const buf2 = buf1.slice(0);