title: Use the Spread Operator to Evaluate Arrays In-Place
challengeType: 1
---
## Description
<sectionid='description'>
ES6 introduces the <dfn>spread operator</dfn>, which allows us to expand arrays and other expressions in places where multiple parameters or elements are expected.
The ES5 code below uses <code>apply()</code> to compute the maximum value in an array:
We had to use <code>Math.max.apply(null, arr)</code> because <code>Math.max(arr)</code> returns <code>NaN</code>. <code>Math.max()</code> expects comma-separated arguments, but not an array.
The spread operator makes this syntax much better to read and maintain.
testString: getUserInput => assert(getUserInput('index').match(/\[\s*...arr1\s*\]/g),'<code>...</code> spread operator was used to duplicate <code>arr1</code>.');