freeCodeCamp/guide/english/certifications/javascript-algorithms-and-d.../basic-data-structures/remove-items-using-splice/index.md

21 lines
580 B
Markdown
Raw Normal View History

2018-10-12 19:37:13 +00:00
---
title: Remove Items Using splice()
---
## Remove Items Using splice()
- The `splice()` function must be called on the `arr` array in order to remove 1 or more elements from the center of the array.
- The array `arr` currently adds up to the value of 16. Simply remove as many variables neccessary to return 10.
## Solution:
```javascript
function sumOfTen(arr) {
// change code below this line
arr.splice(1,2);
// change code above this line
return arr.reduce((a, b) => a + b);
}
// do not change code below this line
console.log(sumOfTen([2, 5, 1, 5, 2, 1]));
```