JavaScript (js) is a light-weight object-oriented programming language which is used by several websites for scripting the webpages. It is an interpreted, full-fledged programming language that enables dynamic interactivity on websites when applied to an HTML document. It was introduced in the year 1995 for adding programs to the webpages in the Netscape Navigator browser. Since then, it has been adopted by all other graphical web browsers. With JavaScript, users can build modern web applications to interact directly without reloading the page every time. The traditional website uses js to provide several forms of interactivity and simplicity.
The splice() method adds/removes items to/from an array, and returns the removed item(s). This method changes the original array.
array.splice(index, howmany, item1, ….., itemX)
index (Required) — An integer that specifies at what position to add/remove items, Use negative values to specify the position from the end of the array
howmany (Optional) — The number of items to be removed. If set to 0, no items will be removed
item1, …, itemX (Optional) — The new item(s) to be added to the array
var fruits = [“Banana”, “Orange”, “Apple”, “Mango”];
fruits.splice(2, 0, “Lemon”, “Kiwi”);
Output: Array [ “Banana”, “Orange”, “Lemon”, “Kiwi”, “Apple”, “Mango” ]
The slice() method returns the selected elements in an array, as a new array object. The slice() method selects the elements starting at the given start argument, and ends at, but does not include, the given end argument. The original array will not be changed.
array.slice(start, end)
start (Optional) — An integer that specifies where to start the selection (The first element has an index of 0). Use negative numbers to select from the end of an array. If omitted, it acts like “0”.
end (Optional) — An integer that specifies where to end the selection. If omitted, all elements from the javascript captcha validation script start position and to the end of the array will be selected. Use negative numbers to select from the end of an array.
var fruits = [“Banana”, “Orange”, “Lemon”, “Apple”, “Mango”];
var citrus = fruits.slice(1, 3);
Output: Array [ “Orange”, “Lemon” ]
var fruits = [“Banana”, “Orange”, “Lemon”, “Apple”, “Mango”];
var citrus = fruits.slice(1, 4);
Output: Array [ “Orange”, “Lemon”, “Apple” ]