SHARE
TWEET

Untitled

a guest Aug 12th, 2017 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var example = ['A', 'B', 'C', 'D'];
  2.  
  3. example.splice(2, 0, 'E');       // remove 0 item, and insert 'E' at 2-index
  4.  
  5. console.log(example);
  6. // ["A", "B", "E", "C", "D"]
  7. var copy = example.splice(2, 1); // remove 1 item at 2-index postion, return the deleted item
  8.  
  9. console.log(copy);
  10. // ["E"]
  11. console.log(example);
  12. // ["A", "B", "C", "D"]
  13. var copy2 = example.splice(2, 0, 'E');
  14.  
  15. console.log(copy2);
  16. // []
  17. console.log(example);
  18. // ["A", "B", "E", "C", "D"]
RAW Paste Data
Top