Typed Array slice()
Examples
// Create a Typed Array
const myArr = Int16Array.from([10,15,20,25,30,35,40,45,50]);
// Slice the Array
const newArr = myArr.slice(2);
Try it Yourself »
// Create a Typed Array
const myArr = Int16Array.from([10,15,20,25,30,35,40,45,50]);
// Slice the Array
const newArr = myArr.slice(2, 5);
Try it Yourself »
Description
The slice()
method returns selected elements in an array, as a new array.
The slice()
method can select from a given start to a given end.
The slice()
method does not change the original array.
Syntax
typed-array.slice(start, end)
Parameters
Parameter | Description |
start | Optional. Start position (inclusive). Default is 0. Negative numbers select from the end of the array. |
end | Optional. End position (exclusive). Default is last element. Negative numbers select from the end of the array. |
Return Value
A new typed array containing the selected elements. |
JavaScript Typed Arrays
Browser Support
typed-array.slice()
is an ECMAScript6 (ES6 2015) feature.
JavaScript 2015 is fully supported in all modern browsers since June 2017:
Chrome 51 | Edge 15 | Firefox 54 | Safari 10 | Opera 38 |
May 2016 | Apr 2017 | Jun 2017 | Sep 2016 | Jun 2016 |