The typedArray.slice() is an inbuilt function in JavaScript which is used to return the part of the elements of the given typedArray.
typedArray.slice(begin, end)
Parameters: It takes two parameter which are specified below-
- begin: It is the beginning index and it can be negative too.
- end: It is the ending index and here slice extracts elements up to but not including end index.
Return value: It returns a new typedArray containing the extracted elements.Â
Example: JavaScript code to show the working of this function.
javascript
| // Creating some typedArray containing same values const A = newUint8Array([ 5, 10, 15, 20, 25 ]); const B = newUint8Array([ 5, 10, 15, 20, 25 ]); const C = newUint8Array([ 5, 10, 15, 20, 25 ]); const D = newUint8Array([ 5, 10, 15, 20, 25 ]); const E = newUint8Array([ 5, 10, 15, 20, 25 ]); const F = newUint8Array([ 5, 10, 15, 20, 25 ]);  Â// Calling slice function with starting and ending index vara = A.slice(1, 2); varb = B.slice(0, 3); varc = C.slice(4); vard = D.slice(0  Â// Here index is negative so it extract element // from the end of the typedArray vare = E.slice(-2); varf = F.slice();  Â// Printing the extracted arrays console.log(a); console.log(b); console.log(c); console.log(d); console.log(e); console.log(f); | 
Output:
10 5,10,15 25 5,10,15,20,25 20,25 5,10,15,20,25


 
                                    







