mozilla

Compare Revisions

Array.prototype.splice()

Change Revisions

Revision 485409:

Revision 485409 by aerotrink on

Revision 502551:

Revision 502551 by fscholz on

Title:
Array splice method
Array.prototype.splice()
Slug:
Web/JavaScript/Reference/Global_Objects/Array/splice
Web/JavaScript/Reference/Global_Objects/Array/splice
Tags:
"Array", "Array methods"
"Array", "Method", "JavaScript", "Prototype"
Content:

Revision 485409
Revision 502551
nn7    <div>
8      {{JSRef("Global_Objects", "Array")}}
9    </div>
n11      Changes the content of an array, adding new elements while n14      The <code><strong>splice()</strong></code> method changes t
>removing old elements.>he content of an array, adding new elements while removing old el
 >ements.
n13    <table class="standard-table">n
14      <thead>
15        <tr>
16          <th class="header" colspan="2">
17            Method of <a href="/en/JavaScript/Reference/Global_Ob
>jects/Array#Array_instances"><code>Array</code> instances</a> 
18          </th>
19        </tr>
20      </thead>
21      <tbody>
22        <tr>
23          <td>
24            Implemented in
25          </td>
26          <td>
27            JavaScript 1.2
28          </td>
29        </tr>
30        <tr>
31          <td>
32            ECMAScript Edition
33          </td>
34          <td>
35            ECMAScript 3rd Edition
36          </td>
37        </tr>
38      </tbody>
39    </table>
n46<code><em>array</em>.splice(<em>index</em>) // SpiderMonkey extenn22<code><em>array</em>.splice(<em>index</em>) // SpiderMonkey/Firef
>sion</code>>ox extension</code>
n75    <h2 id="Returns">n51    <h3 id="Returns">
n77    </h2>n53    </h3>
n86    </p>n
87    <h2 id="Backward_Compatibility">
88      Backward Compatibility
89    </h2>
90    <h3 id="JavaScript_1.2">
91      JavaScript 1.2
92    </h3>
93    <p>
94      The <code>splice</code> method returns the element removed,
> if only one element is removed (<code>howMany</code> parameter i 
>s 1); otherwise, the method returns an array containing the remov 
>ed elements. Note that the last browser to use JavaScript 1.2 was 
> Netscape Navigator 4, so you can depend on <code>splice</code> a 
>lways returning an array. 
nn100    <h2 id="Specifications">
101      Specifications
102    </h2>
103    <table class="standard-table">
104      <tbody>
105        <tr>
106          <th scope="col">
107            Specification
108          </th>
109          <th scope="col">
110            Status
111          </th>
112          <th scope="col">
113            Comment
114          </th>
115        </tr>
116        <tr>
117          <td>
118            ECMAScript 3rd Edition
119          </td>
120          <td>
121            Standard
122          </td>
123          <td>
124            Initial definition.<br>
125            Implemented in JavaScript 1.2
126          </td>
127        </tr>
128        <tr>
129          <td>
130            {{SpecName('ES5.1', '#sec-15.4.4.12', 'Array.prototyp
 >e.splice')}}
131          </td>
132          <td>
133            {{Spec2('ES5.1')}}
134          </td>
135          <td>
136            &nbsp;
137          </td>
138        </tr>
139        <tr>
140          <td>
141            {{SpecName('ES6', '#sec-array.prototype.splice', 'Arr
 >ay.prototype.splice')}}
142          </td>
143          <td>
144            {{Spec2('ES6')}}
145          </td>
146          <td>
147            &nbsp;
148          </td>
149        </tr>
150      </tbody>
151    </table>
152    <h2 id="Browser_compatibility">
153      Browser compatibility
154    </h2>
155    <div>
156      {{CompatibilityTable}}
157    </div>
158    <div id="compat-desktop">
159      <table class="compat-table">
160        <tbody>
161          <tr>
162            <th>
163              Feature
164            </th>
165            <th>
166              Chrome
167            </th>
168            <th>
169              Firefox (Gecko)
170            </th>
171            <th>
172              Internet Explorer
173            </th>
174            <th>
175              Opera
176            </th>
177            <th>
178              Safari
179            </th>
180          </tr>
181          <tr>
182            <td>
183              Basic support
184            </td>
185            <td>
186              1.0
187            </td>
188            <td>
189              {{CompatGeckoDesktop("1.7")}}
190            </td>
191            <td>
192              5.5
193            </td>
194            <td>
195              {{CompatVersionUnknown}}
196            </td>
197            <td>
198              {{CompatVersionUnknown}}
199            </td>
200          </tr>
201        </tbody>
202      </table>
203    </div>
204    <div id="compat-mobile">
205      <table class="compat-table">
206        <tbody>
207          <tr>
208            <th>
209              Feature
210            </th>
211            <th>
212              Android
213            </th>
214            <th>
215              Chrome for Android
216            </th>
217            <th>
218              Firefox Mobile (Gecko)
219            </th>
220            <th>
221              IE Mobile
222            </th>
223            <th>
224              Opera Mobile
225            </th>
226            <th>
227              Safari Mobile
228            </th>
229          </tr>
230          <tr>
231            <td>
232              Basic support
233            </td>
234            <td>
235              {{CompatVersionUnknown}}
236            </td>
237            <td>
238              {{CompatVersionUnknown}}
239            </td>
240            <td>
241              {{CompatVersionUnknown}}
242            </td>
243            <td>
244              {{CompatVersionUnknown}}
245            </td>
246            <td>
247              {{CompatVersionUnknown}}
248            </td>
249            <td>
250              {{CompatVersionUnknown}}
251            </td>
252          </tr>
253        </tbody>
254      </table>
255    </div>
256    <h3 id="Backward_Compatibility">
257      Backward compatibility
258    </h3>
259    <p>
260      The <code>splice</code> method returns the element removed,
 > if only one element is removed (<code>howMany</code> parameter i
 >s 1); otherwise, the method returns an array containing the remov
 >ed elements. Note that the last browser to use JavaScript 1.2 was
 > Netscape Navigator 4, so you can depend on <code>splice</code> a
 >lways returning an array.
261    </p>
n137      <li>n266      <li>{{jsxref("Array.push")}} / {{jsxref("Array.pop")}} - ad
 >d/remove elements from the end of the array;
138        <a href="https://developer.mozilla.org/en-US/docs/JavaScr
>ipt/Reference/Global_Objects/Array/push" title="https://developer 
>.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array 
>/push">push</a> / <a href="https://developer.mozilla.org/en/JavaS 
>cript/Reference/Global_Objects/Array/pop" title="en/JavaScript/Re 
>ference/Global_Objects/Array/pop">pop</a> - add/remove elements f 
>rom the end of the array; 
n140      <li>n268      <li>{{jsxref("Array.unshift")}} / {{jsxref("Array.shift")}}
 > - add/remove elements from the beginning of the array;
141        <a href="https://developer.mozilla.org/en/JavaScript/Refe
>rence/Global_Objects/Array/unshift" title="en/JavaScript/Referenc 
>e/Global_Objects/Array/unshift">unshift</a> / <a href="https://de 
>veloper.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/ 
>shift" title="en/JavaScript/Reference/Global_Objects/Array/shift" 
>>shift</a> - add/remove elements from the beginning of the array; 
t143      <li>t270      <li>{{jsxref("Array.concat")}} - returns a new array compri
 >sed of this array joined with other array(s) and/or value(s).
144        <a href="/en-US/docs/JavaScript/Reference/Global_Objects/
>Array/concat" title="https://developer.mozilla.org/en-US/docs/Jav 
>aScript/Reference/Global_Objects/Array/splice">concat</a> - retur 
>ns a new array comprised of this array joined with other array(s) 
> and/or value(s). 

Back to History