JavaScript 数组 splice方法


JavaScript 数组 splice方法

<html>
   <head>
      <title>JavaScript Array splice Method</title>
   </head>

   <body>

      <script type = "text/javascript">
         var arr = ["orange", "mango", "banana", "sugar", "tea"];

         var removed = arr.splice(2, 0, "water");
         document.write("After adding 1: " + arr );
         document.write("<br />removed is: " + removed);

         removed = arr.splice(3, 1);
         document.write("<br />After adding 1: " + arr );
         document.write("<br />removed is: " + removed);
      </script>

   </body>
</html>