[英]Return a new array with all values except the first, adding 7 to each
How to return a new array with all values except the first, adding 7 to each For example, addSevenToMost([1, 3, 5]) should return [10, 12]如何返回一个包含除第一个值以外的所有值的新数组,每个值加 7 例如,addSevenToMost([1, 3, 5]) 应该返回 [10, 12]
I tried我试过
let arr = [1, 3, 5];
function addSevenToMost(arr) {
let except = 0;
const newArr = arr.filter((value, index) => index !== except);
return newArr;
}
I only managed to get the new array values except the first, now I don't know how to add 7 to each.除了第一个,我只设法得到新的数组值,现在我不知道如何给每个值加 7。
let arr = [1, 3, 5]; let result = arr.slice(1).map(e => e + 7) console.log(result)
const arr = [1, 3, 5] const result = arr.slice(1).map(item => item + 7) console.log(result)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.