Var newText4 = document.createTextNode("After replacing 1st and 2nd furits and adding 'Blackberry', 'Grapefruit', 'Guava', the new list is : " + fruitslist) ĭ(newParagraph4) Var newParagraph4 = document.createElement("p") Var removed_fruits = fruitslist.splice(0, 2,'Blackberry','Grapefruit','Guava') Var newText3 = document.createTextNode("Removed fruit is: " + remove_fruit) ĭ(newParagraph3) Var newParagraph3 = document.createElement("p") Var newText2 = document.createTextNode("After removing 4th fruit, the new list is : " + fruitslist) ĭ(newParagraph2) Var newParagraph2 = document.createElement("p") Var remove_fruit = fruitslist.splice(3, 1) Var newText1 = document.createTextNode("After adding 'Mango' in 3rd place : " + fruitslist) ĭ(newParagraph1) Var newParagraph1 = document.createElement("p") Var remove = fruitslist.splice(2, 0, "Mango") Var newText = document.createTextNode("Fruits List : " + fruitslist) Var newParagraph = document.createElement("p") JS Code var fruitslist = new Array("Orange","Apple","Banana","Chery" ) In the following web document splice() method is used to reproduce the fruits order. If you don't specify any elements, splice simply removes elements from the array. In this case, you should specify at least one new element.Įlement1,element2.,elementN : The elements to add to the array. If removeCount is 0, no elements are removed. RemoveCount: An integer indicating the number of old array elements to remove. StartIndex: Index at which to start changing the array. Syntax splice(startIndex, removeCount, element1,element2., elementN) The splice() method is used to remove old elements and add new elements to an array.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |