Write Arrow Functions with Parameters 2.01

Write Arrow Functions with Parameters 2.01


So I was able to complete the challenge but where does “concat” come from? The variable name is “myConcat”. Appending ‘array 2’ to ‘array 1’ is… arr1.concat(arr2); ??? Is that how you append arrays together? I can only recall the push() shift() unshift() functions but do not understand how arr1.concat(arr2); would result in a single array in this case which has array 1’s contents followed by array 2’s in the same array (example [1, 2] [3, 4, 5] turning into [1, 2, 3, 4, 5].

Your code so far

const myConcat = (arr1, arr2) => arr1.concat(arr2);

// test your code
console.log(myConcat([1, 2], [3, 4, 5]));

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:


Hi Aren, i’ll let MDN explain it since its already written there :slight_smile:

The concat() method is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array.

This means you can assign what it returns to a new variable as well. The important part here is that it merges two arrays, and that a new one (the one generated from the merger) is returned from the method concat()

const arr1 = [a,b,c];
const arr2 = [d,e,f];
let arr3 = arr1.concat(arr2);
console.log(arr3); // [a,b,c,d,e,f]