Skip to content

Commit 2e99655

Browse files
Merge pull request akshitagit#157 from SHIVANATHRIHARIKRISHNA/workbranch
Added splice javascript method to Array Methods
2 parents 07b6ca4 + 7409447 commit 2e99655

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Array Methods/splice.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// splice(index,deleteCount,item1,item2,...)
2+
3+
var number_arr = [ 20, 30, 40, 50, 60 ];
4+
var string_arr = [ "amit", "sumit", "anil", "prateek" ];
5+
6+
// splice()
7+
// deletes 3 elements starting from index1
8+
number_arr.splice(1, 3);
9+
10+
// Insert 3,4,5 at location 1
11+
//Second element 0 indicates no deletion.
12+
number_arr.splice(1, 0, 3, 4, 5);
13+
14+
// deletes two elements starting from index 1
15+
// and add three elements.
16+
// It contains ["amit", "xyz", "geek 1", "geek 2", "prateek"];
17+
string_arr.splice(1, 2, "xyz", "geek 1", "geek 2");
18+
19+
// Printing both the array after performing splice operation
20+
console.log("After splice op " + number_arr);
21+
console.log("After splice op " + string_arr);
22+

0 commit comments

Comments
 (0)