Typed Array subarray()
Examples
// Create a Typed Array
const myArr = Int32Array.of(40, 100, 1, 5, 25, 10);
// Create a Subarray
subArr = myArr.subarray(2);
Try it Yourself »
// Create a Typed Array
const myArr = Int32Array.of(40, 100, 1, 5, 25, 10);
// Create a Subarray
subArr = myArr.subarray(2, 4);
Try it Yourself »
Description
The subarray() method create a new array in the same memory space.
The subarray() method does not change the original array.
Note
The oroginal array and the subarray share the same memory.
Syntax
typed-array.subarray(begin, end)
Parameters
| Parameter | Description |
| begin |
Optional. Element to begin at (inclusive). |
| end |
Optional. Element to end at (exclusive). |
Return Value
| Type | Description |
| Typed Array | A new Typed Array object. |
JavaScript Typed Arrays
Browser Support
typed-array.subarray() is an ECMAScript6 (ES6 2015) feature.
JavaScript 2015 is supported in all browsers since June 2017:
| Chrome 51 |
Edge 15 |
Firefox 54 |
Safari 10 |
Opera 38 |
| May 2016 | Apr 2017 | Jun 2017 | Sep 2016 | Jun 2016 |