Files
2018-10-16 21:32:40 +05:30

593 B
Raw Blame History

title, localeTitle
title localeTitle
Remove Items Using splice() 使用splice删除项目

使用splice删除项目

  • 必须在arr数组上调用splice()函数以便从数组的中心删除1个或多个元素。
  • 数组arr目前的arr值为16.只需删除返回10所需的任意数量的变量。

解:

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]));