2018-10-12 15:37:13 -04:00
---
title: Remove Items from an Array with pop() and shift()
---
2019-07-24 00:59:27 -07:00
# Remove Items from an Array with pop() and shift()
2018-10-12 15:37:13 -04:00
2019-07-24 00:59:27 -07:00
---
## Problem Explanation
2018-10-12 15:37:13 -04:00
- The `.pop()` method and `.shift()` method must be called and initialised using the `popped` and `shifted` variables to return the correct answer from the function.
2019-07-24 00:59:27 -07:00
---
## Solutions
< details > < summary > Solution 1 (Click to Show/Hide)< / summary >
2018-10-12 15:37:13 -04:00
```javascript
function popShift(arr) {
let popped = arr.pop();
let shifted = arr.shift();
return [shifted, popped];
}
// do not change code below this line
2019-07-24 00:59:27 -07:00
console.log(popShift(["challenge", "is", "not", "complete"]));
2018-10-12 15:37:13 -04:00
```
2019-07-24 00:59:27 -07:00
< / details >