<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
let arr = [1, 9, 3, 4, 5]
//reduce 进行累加
let res4 = arr.reduce((acc, item, index, arr) => acc + item)
console.log(res4)
//遍历数组
let res = arr.forEach(function (item, index, arr) {
console.log(item, index, arr)
})
console.log(res)
//进行降序排列
let res1 = arr.sort(function (a, b) {
return b - a
})
console.log(res1)
//取数
let res2 = arr.slice(2, 5)
console.log(res2)
//splice 进行删除
//console.log(arr)
let res3 = arr.splice(1, 2)
console.log(arr)
console.log(arr.splice(1, 0, 'red', 'green'))
console.log(arr)
</script>
</body>
</html>