Open In App

TypeScript | Array shift() Method

Last Updated : 18 Jun, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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 ]

Previous Article
Next Article

Similar Reads

Delete the first element of array without using shift() method in JavaScript
Given an array containing some array elements and the task is to remove the first element from the array and thus reduce the size by 1. We are going to perform shift() method operation without actually using it with the help of JavaScript. There are two approaches that are discussed below: Using splice() MethodUsing filter() MethodMethod 1: Using s
1 min read
What is the use of the Array.shift() method in JavaScript?
The Array.shift() method in JavaScript is used to remove the first element from an array and return that removed element. This method modifies the original array by removing the first element and shifting all subsequent elements to a lower index. Syntax:array.shift()Example: Here, the shift() method is called on the array containing [1, 2, 3, 4, 5]
1 min read
JavaScript Array shift() Method
JavaScript Array shift() Method removes the first element of the array thus reducing the size of the original array by 1. Syntax: arr.shift();Parameters: This method does not accept any parameter. Return Value: This function returns the removed first element of the array. If the array is empty then this function returns undefined. Note: This functi
2 min read
Collect.js shift() Method
The shift() method is used to remove the first element from collection and returns it. Syntax: collect(array).shift() Parameters: The collect() method takes one argument that is converted into the collection and then shift() method is applied on it. Return Value: This method returns the first element of given collection. Below example illustrate th
1 min read
Shift() vs pop() Method in JavaScript
JavaScript shift() and pop() methods are used to remove an element from an array. But there is a little difference between them. The shift() method removes the first element and whereas the pop() method removes the last element from an array. Javascript Array shift() method: The JavaScript Array shift() Method removes the first element of the array
2 min read
Left Shift Assignment (&lt;&lt;=) Operator in JavaScript
The Left Shift Assignment Operator is represented by "&lt;&lt;=". This operator moves the specified number of bits to the left and assigns that result to the variable. We can fill the vacated place by 0. The left shift operator treats the integer stored in the variable to the operator's left as a 32-bit binary number. This can also be explained as
2 min read
Backbone.js shift Collection
In this article, we will discuss Backbone.js shift collection. The Backbone.js pop collection is used to remove and return the first model from the given collection. Syntax: collection.pop(models, options) Parameters: It will take one parameter. options: This parameter takes the model type which will be removed from the given collection. Example 1:
3 min read
PHP | Ds\Sequence shift() Function
The Ds\Sequence::shift() function is an inbuilt function in PHP which is used to removes the first element from the sequence and return it. Syntax: mixed abstract public Ds\Sequence::shift ( void ) Parameters: This function does not accepts any parameter. Return values: This function returns the first value which is removed from the sequence. Below
1 min read
PHP | Ds\Vector shift() Function
The Ds\Vector::shift() function is an inbuilt function in PHP which is used to remove the first element from the vector and return it. Syntax: mixed public Ds\Vector::shift( void ) Parameters: This function does not accept any parameter. Return Value: This function returns the value at index 0. Exception: This function throws UnderflowException if
1 min read
PHP | Ds\Deque shift() Function
The Ds\Deque::shift() function is an inbuilt function in PHP which is used to remove and return the first value of deque. Syntax: mixed Ds\Deque::shift( void ) Parameters: This function does not accept any parameters. Return Value: This function returns the first value of deque which was removed. Below programs illustrate the Ds\Deque::shift() func
1 min read