![]() |
VOOZH | about |
The Array.slice() method in TypeScript is a built-in function used to extract a section of an array and return it as a new array. This method does not alter the original array.
Syntax:
array.slice( begin [,end] ); Parameter: This method accepts two parameters as mentioned above and described below:
Return Value: This method returns the extracted arra.
The below example illustrates the Array slice() method in TypeScriptJS:
Example 1: In this example we defines a numeric array arr, then uses the slice() method to extract a portion of it into val.
Output:
[ 23, 7 ]Example 2: In this example we defines a string array arr, then uses the slice() method to extract portions of the array into val.
Output:
[ 'e', 'k', 's', 'f' ]
[ 'f', 'o', 'r' ]