- 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:-
- <html>
- <head>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- </head>
- <body>
- <h1>shift()</h1>
- <h2>ar=["1st","2nd","3rd","4th"]</h2>
- <input type="button" onclick="ar_sft();" value="shift() in array">
- <script>
- function ar_sft()
- {
- var ar = ["1st", "2nd", "3rd", "4th"];
- //Method 2
- alert("Returned : " + ar.shift()); //remove and return the first value '1st'
- alert("After : " + ar);
- }
- </script>
- </body>
- </html>
The shift in JavaScript:- Geniusofstudent
Reviewed by Network security
on
July 11, 2019
Rating:
No comments: