let array = [1, 2, 3, 4, 5]
/**
* fill(value[, start[, end]])
* value 填充值
* start 开始位置【可选】 默认 0 包含 直接替换了原始数组当前位置值
* end 结束位置 【可选】 默认 length 不包含
*/
const array_fill = array.fill(8, 1, 4)
console.log(array) // [1,8,8,8,5]
console.log(array_fill) // [1,8,8,8,5]
array = [1, 2, 3, 4, 5]
/**
* copyWithin(target[, start[, end]])
* target 复制序列到该位置
* start 开始复制位置【可选】 默认 0 包含 直接替换了原始数组当前位置值
* end 结束复制位置 【可选】 默认 length 不包含
*/
const array_copyWithin = array.copyWithin(1, 4, 5) 把索引4到索引5的值替换到 target 目标位置上
console.log(array) // [1,5,3,4,5]
console.log(array_copyWithin) // [1,5,3,4,5]
reduce
数组求积
let arr =[2,3,5,7]
let result= arr.reduce(function(x,y){
return x*y
})
console.log(result) //210