1var array=[1,2,3,4,5];
2console.log(array.splice(2));
3// shows [3, 4, 5], returned removed item(s) as a new array object.
4
5console.log(array);
6// shows [1, 2], original array altered.
7
8var array2=[6,7,8,9,0];
9console.log(array2.splice(2,1));
10// shows [8]
11
12console.log(array2.splice(2,0));
13//shows [] , as no item(s) removed.
14
15console.log(array2);
16// shows [6,7,9,0]
17
18var array3=[11,12,13,14,15];
19console.log(array3.splice(2,1,"Hello","World"));
20// shows [13]
21
22console.log(array3);
23// shows [11, 12, "Hello", "World", 14, 15]
24
25 -5 -4 -3 -2 -1
26 | | | | |
27var array4=[16,17,18,19,20];
28 | | | | |
29 0 1 2 3 4
30
31console.log(array4.splice(-2,1,"me"));
32// shows [19]
33
34console.log(array4);
35// shows [16, 17, 18, "me", 20]
36