10.07.2017 Views

javascript_tutorial

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Javascript<br />

<br />

<br />

howMany: An integer indicating the number of old array elements to<br />

remove. If howMany is 0, no elements are removed.<br />

element1, ..., elementN: The elements to add to the array. If you don't<br />

specify any elements, splice simply removes the elements from the array.<br />

Return Value<br />

Returns the extracted array based on the passed parameters.<br />

Example<br />

Try the following example.<br />

<br />

<br />

JavaScript Array splice Method<br />

<br />

<br />

<br />

var arr = ["orange", "mango", "banana", "sugar", "tea"];<br />

var removed = arr.splice(2, 0, "water");<br />

document.write("After adding 1: " + arr );<br />

document.write("removed is: " + removed);<br />

removed = arr.splice(3, 1);<br />

document.write("After adding 1: " + arr );<br />

document.write("removed is: " + removed);<br />

<br />

<br />

<br />

Output<br />

After adding 1: orange,mango,water,banana,sugar,tea<br />

removed is:<br />

After adding 1: orange,mango,water,sugar,tea<br />

removed is: banana<br />

217

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!