2. push(): Adds one or more elements to the end of an array and returns the new length of the array.
3. splice() method:
The splice() method adds/removes items to/from an array, and returns the removed item(s) and change the content of an array, adding new elements while removing old elements. Splice method adds new element to existing an array and remove an element from to existing array and then add the removed element to new an array.
array.splice(index, howMany, [item1][, …, itemN]);
Where index − Index at which to start changing the array. howMany − total number of old array elements to remove. If howMany is 0, no elements are removed. item1, …, itemN − Optional, and the elements to be added to the array. If you don’t specify any elements, splice simply removes the elements from the array.
Note: This method changes the original array.
In this example, we are removing one element at second index and adding two new an element at companies array index 2. The resulting array element of companies is Apple,Google,Infosys,TCL,IBM, and where second element Facebook is remove from an array list.
Example 2: Here we are removing the element from the existing array and add the removed element to a new array called sliced.
Output of the above code, oldArray :[ “zero”,”one”] and new sliced : “[two”,”three”]
To remove an item from the list