Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function shiftArray(arr) {
- // remove 1 item at 0-index position, return the deleted item
- return arr.splice(0, 1);
- }
- var a = [1, 2, 3];
- var b = a.shift();
- console.log(a); // [2, 3]
- console.log(b); // 1
- var c = shiftArray(a);
- console.log(a); // [3]
- console.log(c); // [2]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement