- This method is used to add/remove items to/from an array.
- Method will return the removed items in n array.
- This method used to change the original array.
Code:-
- <html>
- <head>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- </head>
- <body>
- <h1>splice</h1>
- <h2>ar = ["red","green","Apricot","Guava"]</h2>
- <input type="button" onclick="ar_sl();" value="splice array">
- <script>
- function ar_sl()
- {
- var ar = ["red", "green", "Apricot", "Guava"];
- alert(ar.splice(0, 2, "Apple", "Banana")); // index 0 to 2 values removed completely and return the removed values 'red green' replace with Apple Banana
- alert(ar);
- }
- </script>
- </body>
- </html>
Splice in Array:- Geniusofstudent
Reviewed by Network security
on
August 06, 2019
Rating:
No comments: