Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var example = ['A', 'B', 'C', 'D'];
- example.splice(2, 0, 'E'); // remove 0 item, and insert 'E' at 2-index
- console.log(example);
- // ["A", "B", "E", "C", "D"]
- var copy = example.splice(2, 1); // remove 1 item at 2-index postion, return the deleted item
- console.log(copy);
- // ["E"]
- console.log(example);
- // ["A", "B", "C", "D"]
- var copy2 = example.splice(2, 0, 'E');
- console.log(copy2);
- // []
- console.log(example);
- // ["A", "B", "E", "C", "D"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement