--- id: 587d7b7b367417b2b2512b17 title: Combine Arrays with the Spread Operator challengeType: 1 videoUrl: '' localeTitle: 将数组与Spread运算符组合在一起 --- ## Description
扩展运算符的另一个巨大优势是能够组合数组,或者在任何索引处将一个数组的所有元素插入到另一个数组中。使用更传统的语法,我们可以连接数组,但这只允许我们在一个数组的末尾和另一个数组的开头组合数组。 Spread语法使以下操作非常简单:
让thisArray = ['sage','迷迭香','欧芹','百里香'];

让那个阵容= ['罗勒','香菜',......这个阿雷,'香菜'];
//现在等于['罗勒','香菜','鼠尾草','迷迭香','欧芹','百里香','香菜']
使用扩展语法,我们刚刚实现了一个操作,如果我们使用传统方法,这个操作会更复杂,更冗长。
## Instructions
我们定义了一个函数spreadOut ,它返回变量sentence ,使用spread运算符修改函数,使它返回数组['learning', 'to', 'code', 'is', 'fun']
## Tests
```yml tests: - text: 'spreadOut应该返回["learning", "to", "code", "is", "fun"]' testString: 'assert.deepEqual(spreadOut(), ["learning", "to", "code", "is", "fun"], "spreadOut should return ["learning", "to", "code", "is", "fun"]");' - text: spreadOut函数应该使用扩展语法 testString: 'assert.notStrictEqual(spreadOut.toString().search(/[...]/), -1, "The spreadOut function should utilize spread syntax");' ```
## Challenge Seed
```js function spreadOut() { let fragment = ['to', 'code']; let sentence; // change this line return sentence; } // do not change code below this line console.log(spreadOut()); ```
## Solution
```js // solution required ```