A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice below:

ArrayBuffer.prototype.slice() - JavaScript | MDN

ArrayBuffer.prototype.slice()

Baseline Widely available

ArrayBuffer 实例的 slice() 方法返回一个新的 ArrayBuffer 实例,其包含原 ArrayBuffer 实例中从 begin 开始(包含)到 end 结束(不含)的所有字节的副本。

尝试一下
// Create an ArrayBuffer with a size in bytes
const buffer = new ArrayBuffer(16);
const int32View = new Int32Array(buffer);
// Produces Int32Array [0, 0, 0, 0]

int32View[1] = 42;
const sliced = new Int32Array(buffer.slice(4, 12));
// Produces Int32Array [42, 0]

console.log(sliced[0]);
// Expected output: 42
语法
slice()
slice(start)
slice(start, end)
参数
start 可选

要开始提取的位置索引(从 0 开始),将被转换为整数。

end 可选

要结束提取的位置索引(从 0 开始),将被转换为整数。slice() 提取到但不包括 end。

返回值

一个新的 ArrayBuffer 对象。

示例 复制一个 ArrayBuffer
const buf1 = new ArrayBuffer(8);
const buf2 = buf1.slice(0);
规范 浏览器兼容性 参见

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4