splice : Remove elements from an array and replace it with new elements
splice(array, start[, length]);
This function remove elements from an array and replace it with new elements
This function returns a new array.
input = ["red", "green", ["blue", "yellow"], 1.0, { "x" : 1 }, 4];
input.splice(4, 1, "purple");
return ["red","green",["blue","yellow"],1,"purple",4] which replace the 4th element by the value "purple"
input = ["red", "green", "blue", "yellow"];
input.splice(3, 0, "purple");
return ["red","green","blue","purple","yellow"] which insert an element at position 3.
input = ["red", "green", "blue", "yellow"];
splice(input, -1, 1, "black", "maroon");
["red","green","blue","black","maroon"\]
input = ["red", "green", "blue", "yellow"];
splice(input, 1, length(input), "orange");
["red","orange"\]
input = ["red", "green", "blue", "yellow"];
input.splice(1, -1);
["red","yellow"\]
input = ["red", "green", "blue", "yellow"];
input.splice(2);
["red","green"\]
fruits = ["Banana", "Orange", "Apple", "Mango", "Kiwi"];
fruits.splice(fruits.length()-1, 1, 2, 3, 4);
["Banana","Orange","Apple","Mango",2,3,4\]
fruits = ["Banana", "Orange", "Apple", "Mango", "Kiwi"];
fruits.splice(0, 5, 1, 2, 3, 4);
[1,2,3,4\]
fruits = ["Banana", "Orange", "Apple", "Mango", "Kiwi"];
fruits.splice(0, 5);
[\]
fruits = ["Banana", "Orange", "Apple", "Mango", "Kiwi"];
fruits.splice(-200, -200);
["Banana","Orange","Apple","Mango","Kiwi"\]
fruits = ["Banana", "Orange", "Apple", "Mango", "Kiwi"];
fruits.splice(200, 200);
["Banana","Orange","Apple","Mango","Kiwi"\]
fruits = ["Banana", "Orange", "Apple", "Mango", "Kiwi"];
fruits.splice(2, 2);
["Banana","Orange","Kiwi"\]
fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.splice(2, 1, "Lemon", "Kiwi");
["Banana","Orange","Lemon","Kiwi","Mango"\]
fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.splice(2, 0, "Lemon", "Kiwi");
["Banana","Orange","Lemon","Kiwi","Apple","Mango"\]
a = [1,2,3,4,5,6];
x=a.splice(1, 2, 7,8,9);
a[1]=333;
a;
x;
[1,333,3,4,5,6\]\[1,7,8,9,4,5,6\]
Written by Pierre Laplante, <laplante@sednove.com>
Available from version 5.90
Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis.
1.0 2014-09-09 21:24:14 laplante@sednove.com