1.rest参数的使用(…args)
ES6中引入rest参数,用于获取函数的参数,用来代替arguments
//arguments
// function data1() {
// console.log(arguments)
// }
// data1(12, 5, 3)
// //rest参数
// function data2(...args) {
// console.log(args)
// }
// data2(1, 2, 3)
// function data3(a, b, ...args) {
// console.log(a);
// console.log(b)
// console.log(args)
// }
// data3(7, 8, 1, 9, 1)
const arr = ['nihao', 'wohao', 'dajiahao']
function hao() {
console.log(arguments)
}
hao(...arr)
2.扩展运算符
扩展运算符能将【数组】转换为逗号分割的【参数序列】
<script>
// 扩展运算符的使用
//1.拼接数组
const arr1 = ['piaoliang', 'keai'];
const arr2 = ['wenrou', 'dafang']
const arr3 = [...arr1, ...arr2]
console.log(arr3)
console.log("****************分隔符*********************")
//2.拷贝数组(浅拷贝)
const sanzhihua = ['E', 'G', 'M']
const sanzhihua1 = [...sanzhihua]
console.log(sanzhihua1)
//将伪数组转换为真正的数组
const divs = document.querySelectorAll('div')
console.log(divs)
const divArr = [...divs]
console.log(divArr)
</script>