Hey, all! First post! Anyway, I am stuck on this particular problem. I feel like my answer is doing what is asked in the questions but for some reason it’s not passing. In the output, it will notify me that
... spread operator was used to duplicate arr1.. Am I missing something or is this a bug? Thanks in advance for the assistance!
Your code so far
const arr1 = ['JAN', 'FEB', 'MAR', 'APR', 'MAY'];
const arr2 = ;arr2.push(...arr1); // change this line
console.log(arr2); // arr2 should not be affected
Your browser information:
User Agent is:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36.
Link to the challenge:
Why are you adding
Why do you have
const arr2 = ;arr2.push(...arr1); jammed into one line?
Because the problem says to change that line, I assume.
You are making this Waaay harder than it actually is. Reset the problem, read the instructions again, and think simple. Perhaps you just need to put something inside those brackets when declaring arr2?
Take a look at the video put in the hints of the challenge, it will help you understand how it works
check out the mdn docs for spread operator. Spread returns a new array and doesnt affect original push concatenates onto array. Usually people use spread when working with immutable data eg in React.
I dont know what challenge asking doing but probably something like this.
const arr1 = [‘JAN’, ‘FEB’, ‘MAR’, ‘APR’, ‘MAY’];
const addMonth = “JUN”;
const arr2 = […arr1, addMonth];
or instead off using the addMonth const just do
const arr3 = […arr2, “DEC”];
// arr1 remains untouched.
Thanks for the help, all! Going to read through the MDN and other sources given. Thanks!
Figured it out!
I guess I was working too hard. Instead of trying to push
arr2, I just needed to instantiate
arr2 like follows:
arr2 = [...arr1]
For whatever reason, I thought this would return an error because I thought the spread operator needed to be used as an argument to a function…my bad!