Multifunction splice () Insert, delete, replace
<script type= "Text/javascript" > var arr=[' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G ']; Arr.splice (3, 2, ' apples ', ' grapes '); Replace some items console.log (arr); </script>
<script type= "Text/javascript" > // change some items var arr=[' A ', ' B ', ' C ', ' d ', ' e ', ' F ', ' G '] arr.splice (3,2, ' x ', ' y ', ' x ', ' Password ');//Change some items console.log (arr); </script>
<script type= "Text/javascript" > var arr=[' A ', ' B ', ' C ', ' d ', ' e ', ' f ', ' G '] arr.splice (2, 1, ' haha '); // change an item Console.log (arr); </script>
<script type= "Text/javascript" > var arr=[' A ', ' B ', ' C ', ' d ', ' e ', ' f ', ' G ']; Arr.splice (/// Nothing can be replaced, delete console.log (arr) directly; </script>
<script type= "Text/javascript" > var arr=[' A ', ' B ', ' C ', ' d ', ' e ', ' f ', ' G ']; Arr.splice (2); Console.log (arr); </script>
<script type= "Text/javascript" > var arr=[' A ', ' B ', ' C ', ' d ', ' e ', ' f ', ' G ']; Arr.splice (// Insert some item console.log (arr); </script>
Second, case: Delete array last five items
<script type= "Text/javascript" > // Delete array last five items var arr[' A ', ' B ', ' C ', ' d ', ' e ', ' F ', ' G ']; Arr.pop (); Arr.pop (); Arr.pop (); Arr.pop (); Arr.pop (); // simplified to for (var i=0; i<arr.length; i++;) { arr[i].pop (); } // can also Arr.splice ( -5); Console.log (arr); </script>
Array multifunction Splice () method Insert, delete, replace