… 稱為 “展開(kāi)運(yùn)算符” (spread operator),它可以將數(shù)組或?qū)ο笳归_(kāi)成一個(gè)列表或一組鍵值對(duì),常用于組合兩個(gè)或多個(gè)陣列。文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-732571.html
const arr = [1, 5, 3, 8, 2]
console.log(...arr)//1 5 3 8 2
說(shuō)明:不會(huì)修改原數(shù)組文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-732571.html
典型運(yùn)用場(chǎng)景
求最大最小值
Math.max(...arr)
Math.min(...arr)
合并數(shù)組
const arr1 = [1, 2, 3]
const arr2 = [4, 5, 6]
const arr = [...arr1, ...arr2] // [1, 2, 3, 4, 5, 6]
?組合對(duì)象
const obj1 = {a: 1, b: 2};
const obj2 = {...obj1, c: 3, d: 4}; // {a: 1, b: 2, c: 3, d: 4}
函數(shù)賦值
function myFunction(x, y, z) {
console.log(x + y + z);
}
const arr = [1, 2, 3];
myFunction(...arr); // 6
?解構(gòu)賦值
let [a, ...b] = [1, 2, 3, 4] //a==1, b==[2, 3, 4]
到了這里,關(guān)于ES6-擴(kuò)展運(yùn)算符“...“的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!