返回 ArrayBuffer 的一部分。
## 語法
~~~
arrayBufferObj.slice(start, [end])
~~~
## 參數
|參數|定義|
|--|--|
|arrayBufferObj|必需。該部分將從中復制的 ArrayBuffer 對象。|
|start|必需。要復制的開頭部分的字節索引。|
|end|可選。要復制的結尾部分的字節索引。|
## 備注
slice 方法將返回包含 arrayBufferObj 指定部分的 ArrayBuffer 對象。
slice 方法可以復制最多(但不包括) end 指示的字節。如果 start 或 end 為負,指定的索引將分別被視為 length + start 或 end,其中 length 是 ArrayBuffer 的長度。如果省略了 end,將繼續提取,直到 arrayBufferObj 的結尾。如果 end 出現在 start 之前,則不會將任何字節復制到新的 ArrayBuffer。
下面的示例演示如何使用 slice 方法。
~~~
var req = new XMLHttpRequest();
req.open('GET', "http://www.example.com");
req.responseType = "arraybuffer";
req.send();
req.onreadystatechange = function () {
if (req.readyState === 4) {
var buffer1 = req.response;
var buffer2 = buffer1.slice(40, 48);
var dataview = new DataView(buffer2);
var ints = new Int32Array(buffer2.byteLength / 4);
for (var i = 0; i < ints.length; i++) {
ints[i] = dataview.getInt32(i * 4);
}
alert(ints[1]);
}
}
~~~
- ActiveXObject對象
- Array對象
- constructor屬性
- length屬性
- prototype屬性
- Array.from函數
- Array.isArray函數
- Array.of函數
- concat方法
- entries方法
- every方法
- fill方法
- filter方法
- findIndex方法
- forEach方法
- indexOf方法
- join方法
- keys方法
- lastIndexOf方法
- map方法
- pop方法
- push方法
- reduce方法
- reduceRight方法
- reverse方法
- shift方法
- slice方法
- some方法
- sort方法
- splice方法
- toString方法
- unshift方法
- valueOf方法
- values方法
- ArrayBuffer對象
- byteLength屬性
- ArrayBuffer.isView函數
- slice方法
- arguments對象
- 0...n 屬性(參數)
- callee 屬性(參數)
- length 屬性 (arguments)
- Boolean對象
- constructor 屬性(布爾值)
- prototype 屬性(布爾值)
- toString 方法 (Boolean)
- valueOf 方法 (Boolean)
- DataView對象
- buffer屬性 (DataView)
- byteLength屬性(DataView)
- byteOffset屬性(DataView)
- getInt8方法(DataView)
- getUint8方法(DataView)
- getInt16方法(DataView)
- getUint16方法(DataView)
- getInt32方法(DataView)
- getUint32方法(DataView)
- getFloat32方法(DataView)
- getFloat64方法(DataView)
- setInt8方法(DataView)
- setUint8方法(DataView)
- setInt16方法(DataView)
- setUint16方法(DataView)
- setInt32方法(DataView)
- setUint32方法(DataView)
- setFloat32方法(DataView)
- setFloat64方法(DataView)
- Date對象
- Debug對象
- Enumerator對象
- Error對象
- Float32Array對象
- Float64Array對象
- Function對象
- Global對象
- Int8Array對象
- Int16Array對象
- Int32Array對象
- Intl.Collator對象
- Intl.DateTimeFormat對象
- Intl.NumberFormat對象
- JSON對象
- Map對象
- Math對象
- Number對象
- Object對象
- Promise對象
- 代理對象
- Reflect對象
- RegExp對象
- 正則表達式對象
- Set對象
- String對象
- 符號對象
- Uint8Array對象
- Uint8ClampedArray對象
- Uint16Array對象
- Uint32Array對象
- VBArray對象
- WeakMap對象
- WeakSet對象
- WinRTError對象