DEV Community

Cover image for Concatenate new array
chandra penugonda
chandra penugonda

Posted on

Concatenate new array

Implement a function that takes an array and additional arrays and/or values as arguments and returns a new array by concatenating them together.

Example

function customConcat(array, ...values) {

}

var array = [1];
console.log(customConcat(array, 2, [3], [[4]]));
// [1, 2, 3, [4]]
Enter fullscreen mode Exit fullscreen mode

Solution

function customConcat(array, ...values) {
  return array.concat(...values)
}

var array = [1];
console.log(customConcat(array, 2, [3], [[4]]));
// [1, 2, 3, [4]]
Enter fullscreen mode Exit fullscreen mode

Top comments (0)