The shift in JavaScript:- Geniusofstudent

  • The shift() method will remove the first item of an array, and it will return that item.
  • This method changes the length of an array.

Code:-
  • <!DOCTYPE html> 
    1. <html> 
    2.  
    3. <head> 
    4.  <meta name="viewport" content="width=device-width, initial-scale=1"> 
    5. </head> 
    6.  
    7. <body> 
    8.  <h1>shift()</h1> 
    9.  <h2>ar=["1st","2nd","3rd","4th"]</h2> 
    10.  
    11.  <input type="button" onclick="ar_sft();" value="shift() in array"> 
    12.  
    13.  <script> 
    14.   function ar_sft() 
    15.   { 
    16.  
    17.    var ar = ["1st", "2nd", "3rd", "4th"]; 
    18.  
    19.    //Method 2 
    20.    alert("Returned : " + ar.shift()); //remove and return the first value '1st' 
    21.  
    22.    alert("After : " + ar); 
    23.  
    24.   } 
    25.  </script> 
    26.  
    27. </body> 
    28.  
    29. </html>

    The shift in JavaScript:- Geniusofstudent The shift in JavaScript:- Geniusofstudent Reviewed by Network security on July 11, 2019 Rating: 5

    No comments:

    Useful Information

    Powered by Blogger.