The Javascript TypedArray subarray() method is used to get a new array of selected elements without changing the original array.
Syntax:
array.subarray(start, end)
Parameters:
start: It represents the index position where to start the selection.
end: It represents the index position where to end the selection.
Returns:
It returns a new array of selected elements.
Example 1:
<!DOCTYPE html>
<html>
<body>
<script>
function func() {
var num = new Uint8Array([31,32,34,53,83]);
var sub = num.subarray(2,4);
document.write(sub); }
func();
</script>
</body>
</html>
Example 2:
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
const testArray = new Uint8Array([12, 23, 34, 45, 67]);
document.write(testArray.subarray(1, 3));
document.write("</br>");
document.write(testArray.subarray(1));
</script>
</body>
</html>