Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Javascript Shifting Elements

    • 0
    • 1
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 94
    Comment on it

    The shift() method is used to remove the first element of an array from the zero index and shift to the consecutive index and this is also used to change the length of an array .
    syntax :
    array.shift();

    Example :

    var arr = ['Mukesh', 'Ayush', 'Ravi' ] ;
    alert(" before shift() method " + arr);//output : Mukesh Ayush Ravi
    var shifting =  arr.shift();
    alert("after using shift() method" + arr) ; //output : Ayush Ravi
    

    If you want to see Removed element from an array, you can see with the help of shifted element.

    Example :

    alert(" Removed Element is " + arr); //output :Mukesh 
    

    Note
    If the lenght of an array is zero, then it will return undefined

 1 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: