CodesJava

Easy learning with example program codes

TypedArray Slice() JavaScript

The Javascript TypedArray Slice() method is used to get the selected elements of the array on which is implemented.

Syntax:

Array.slice(start, end) 

Parameters:
start: It represents index position where to start the selection.
end: It represents the index position where to end the selection.

Returns:
It returns a new array that contains selected part of the source array.

Example 1:

<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">   
var array = [100,200,300,400,500];  
var sliced = array.slice(1);  	 
document.write(sliced);  
</script>
</body>
</html>

Output:

200,300,400,500

Example 2:

<!DOCTYPE html>
<html>
<body>
<script type="text/javascript"> 
const testArray1 = new Uint8Array([34, 12, 56, 14, 67]);
var testArray2 = testArray1.slice(1, 3);
 
document.write(testArray2);
 
</script>
</body>
</html>

Output:

12,56
Please follow and like us:
error








Copyright © 2019 CodesJava DMCA.com Protection Status