<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
let arr1=[1,2,3,4,5]
let arr2=[2,4,6,8,10]
console.log(...arr1)
let arr3=[...arr1,...arr2]
//2、在函数中使用
function sum(...nums){
return nums.reduce((preValue,currentValue) => {
return preValue+currentValue
})
}
console.log(sum(1,2,3,4))
//3、构造对象使用展开语法
let person={name:'Tom',age:18}
let person2={...person}
// console.log(...person) //报错,展开运算符不能展开对象
person.name='jerry'
console.log(person2)
console.log(person)
//合并
let person3={...person,name:'jerry',address:'地球'}
</script>
</body>
</html>
展开运算符
最新推荐文章于 2023-05-04 21:33:12 发布