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)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay