es6:Spread Operator展開運算子
阿新 • • 發佈:2018-11-21
//組裝物件或者陣列
const color =["red","blue"];
const colorful=[...color,'green','pink']
console.log(colorful)
const alp= {first:"a",second:"b"}
const alphabets={...alp,third:'c'}
console.log(alphabets);
//獲取陣列或者物件除了前幾項或者除了某幾項的其他項
const number=[1,2,3,4,5] const [first,...rest]=number; console.log(rest); const user ={ username:'abc', gender:'fee', age:11, address:"asdasda" } const {age,...rest1}=user console.log(rest1)
//Object ,還可以用於組合成新的 Object 。如果有重複的屬性名,右邊覆蓋左邊。
const arr1={
a:1,
b:2,
c:3,
}
const arr2={
c:4,
d:5,
}
const total={...arr1,...arr2}
console.log(total)