freeCodeCamp/guide/english/certifications/javascript-algorithms-and-d.../basic-data-structures/remove-items-from-an-array-.../index.md

19 lines
529 B
Markdown
Raw Normal View History

2018-10-12 19:37:13 +00:00
---
title: Remove Items from an Array with pop() and shift()
---
## Remove Items from an Array with pop() and shift()
- 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.
## Solution:
```javascript
function popShift(arr) {
let popped = arr.pop();
let shifted = arr.shift();
return [shifted, popped];
}
// do not change code below this line
console.log(popShift(['challenge', 'is', 'not', 'complete']));
```