TypeScript | Array shift() Method
The Array.shift() is an inbuilt TypeScript function which is used to remove the first element from an array and returns that element.
Syntax:
array.shift();
Parameter: This methods does not accept any parameter.
Return Value: This method returns the removed single value of the array.
Below example illustrate the Array shift() method in TypeScriptJS:
Example 1:
JavaScript
<script>
var arr = [ 11, 89, 23, 7, 98 ];
var val = arr.shift();
console.log( val );
console.log( arr );
</script>
|
Output:
11
[ 89, 23, 7, 98 ]
Example 2:
JavaScript
<script>
var arr = [2, 5, 6, 3, 8, 9];
var val;
val = arr.shift();
console.log( val );
val = arr.shift();
console.log( val );
console.log( arr );
</script>
|
Output:
2
5
[ 6, 3, 8, 9 ]
Last Updated :
18 Jun, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...