Requirements: Use array arr2 to overwrite all elements in array arr1 when encapsulating Plug-ins
Definitions and usage
The splice () method inserts, deletes, or replaces the elements of an array.
Grammar
Arrayobject.splice (index,howmany,element1,....., elementx)
Example 1
In this case, we'll create a new array and add an element to it:
The code is as follows |
Copy Code |
<script type= "Text/javascript" > var arr = new Array (6) Arr[0] = "George" ARR[1] = "John" ARR[2] = "Thomas" ARR[3] = "James" ARR[4] = "Adrew" ARR[5] = "Martin" document.write (arr + "<br/>") Arr.splice (2,0, "William") document.write (arr + "<br/>") </script> output: George,john,thomas,james,adrew,martin George,john,william,thomas,james,adrew,martin |
All right, it's just a brief introduction to this source, so let's introduce the splice () method to implement overlay arrays
Instance source code
code is as follows |
copy code |
<div id= "Demo" ></div> <script type= "Text/javascript" var arr1 =["element 1", "Element 2"; var arr2 =["arr2-element 1 "," arr2-element 2 "]; Arr1.splice (0,ARR1.LENGTH,ARR2); document.getElementById ("Demo"). Innerhtml=arr1; </script> |