* change es6 challenges rest operator to param * fix rest parameter typos * change rest operator to parameter in guide * fix casing * change rest operator to rest parameter in guide * change rest operator to rest parameter in curriculum * remove extra whitespace * remove whitespaces * remove whitespace * fix: removed arabic file * fix: removed chinese file
1.8 KiB
1.8 KiB
title
title |
---|
Use the Spread Operator to Evaluate Arrays In-Place |
Use the Spread Operator to Evaluate Arrays In-Place
Spread Operator explained
Mozilla Developer Network Spread Operator
Spread Operator compared to Rest Parameter
Video Explaining Spread Operator and Rest Parameter
Information About apply() Method
Mozilla Developer Network Apply Method
3 Quick Examples
let numbers = [-12, 160, 0, -3, 51];
let minNum = Math.min.apply(null, numbers);
console.log(minNum);//-12
let numbers = [-12, 160, 0, -3, 51];
let minNum = Math.min(numbers);
console.log(minNum);//NaN
let numbers = [-12, 160, 0, -3, 51];
let minNum = Math.min(...numbers);
console.log(minNum);//-12
SPOILER WARNING: SOLUTION AHEAD
The Solution
Unpacking the arr1 using the spread operator and then copying those values to arr2
const arr1 = ['JAN', 'FEB', 'MAR', 'APR', 'MAY'];
let arr2;
(function() {
"use strict";
arr2 = [...arr1]; // change this line
})();
console.log(arr2);