javascript ES6 - `...`传播运算符

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript ES6 - `...`传播运算符相关的知识,希望对你有一定的参考价值。

const avengers = ['Thor', 'The Hulk', 'Captain America'];
let guardians = ['Star Lord', 'Gamorra', 'Drax', 'Rocket', 'Groot'];
// Spread out arrays in a new array and put a new value in between them
const heroes = [...avengers, 'Loki', ...guardians];

// Adding new stuff to an array just got easier too
guardians = [...guardians, 'Mantis', 'Yondu', 'Nebula'];

// Or simply making a TRUE copy of an array
const avengersCopy = [...avengers];

// We can also get everything out of an array in an object
const xmen = {
    team: 'Marvel',
    leader: 'Xavier',
    members: ['Jean Grey', 'Cyclopse', 'Beast', 'Gambit', 'Rogue', 'Wolverine'],
}

// This creates another true copy of the Array with new values in it. 
const xMenSpecial = ['Gambit', 'Mystique', 'Magneto', ...xmen.members];

以上是关于javascript ES6 - `...`传播运算符的主要内容,如果未能解决你的问题,请参考以下文章

dict 在 python 3 中传播(ES6 javascript like , ... notation)

不传播的原因是啥(es 6传播运算符)javascript错误对象[重复]

前端开发技能 —— JavaScript / ES6

markdown es6传播不变的cheatsheet

Javascript 传播与继承

什么是ES6?