Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

TypeScript | Array shift() Method

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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>
   // Driver code
    var arr = [ 11, 89, 23, 7, 98 ]; 
  
    // use of shift() method 
    var val = arr.shift();
       
    // printing
    console.log( val );
    console.log( arr );
</script>

Output: 

11
[ 89, 23, 7, 98 ]

Example 2: 

JavaScript




<script>
   // Driver code
    var arr = [2, 5, 6, 3, 8, 9]; 
    var val;
   
    // use of reverse() method 
    val = arr.shift();
    console.log( val );
    val = arr.shift();
    console.log( val );
       
    // printing
    console.log( arr );
</script>

Output: 

2
5
[ 6, 3, 8, 9 ]
My Personal Notes arrow_drop_up
Last Updated : 18 Jun, 2020
Like Article
Save Article
Similar Reads
Related Tutorials