Splice in Array:- Geniusofstudent

  • 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:-

  • <!DOCTYPE html> 
    1. <html> 
    2.  
    3. <head> 
    4.  <meta name="viewport" content="width=device-width, initial-scale=1"> 
    5. </head> 
    6.  
    7. <body> 
    8.  
    9.  <h1>splice</h1> 
    10.  <h2>ar = ["red","green","Apricot","Guava"]</h2> 
    11.  
    12.  <input type="button" onclick="ar_sl();" value="splice array"> 
    13.  
    14.  <script> 
    15.   function ar_sl() 
    16.   { 
    17.    var ar = ["red", "green", "Apricot", "Guava"]; 
    18.  
    19.    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 
    20.    alert(ar); 
    21.   } 
    22.  </script> 
    23.  
    24. </body> 
    25.  
    26. </html>

    Splice in Array:- Geniusofstudent Splice in Array:- Geniusofstudent Reviewed by Network security on August 06, 2019 Rating: 5

    No comments:

    Useful Information

    Powered by Blogger.