slice() method returns a new ArrayBuffer whose contents are a copy of this ArrayBuffer 's bytes from begin , inclusive, up to end , exclusive.

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

句法

arraybuffer.slice(begin[, end])
					

参数

begin

Zero-based byte index at which to begin slicing.

end 可选
Byte index before which to end slicing. If end is unspecified, the new ArrayBuffer contains all bytes from begin to the end of this ArrayBuffer .

返回值

A new ArrayBuffer 对象。

描述

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, as opposed to from the beginning.

The range specified by the begin and end parameters is clamped to the valid index range for the current array. If the computed length of the new ArrayBuffer would be negative, it is clamped to zero.

范例

Copying an ArrayBuffer

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

规范

规范
ECMAScript (ECMA-262)
The definition of 'ArrayBuffer.prototype.slice' in that specification.

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
slice Chrome 17 Edge 12 Firefox 12
12
The non-standard ArrayBuffer.slice() method has been removed in Firefox 53 (but the standardized version ArrayBuffer.prototype.slice() is kept.
IE 11 Opera 12.1 Safari 6 WebView Android ≤37 Chrome Android 18 Firefox Android 14
14
The non-standard ArrayBuffer.slice() method has been removed in Firefox 53 (but the standardized version ArrayBuffer.prototype.slice() is kept.
Opera Android 12.1 Safari iOS 6 Samsung Internet Android 1.0 nodejs 0.12

图例

完整支持

完整支持

见实现注意事项。

另请参阅

元数据

  • 最后修改: