How to merge/concat two arrays together in JS?

JavaScript: How to merge/concat two arrays together in JS?

To merge two arrays together in Javascript, use the .concat([]) method.

  1. let first_array = [1,2,3,4,5];
  2. let second_array = ["a","b","c"];
  4. console.log(first_array.concat(second_array));

(8) [1, 2, 3, 4, 5, "a", "b", "c"]
webdevetc profile pic

I am a 29 year old backend web developer from London, mostly focusing on PHP and Laravel lately. This ( is my blog where I write about some web development topics (PHP, Laravel, Javascript, and some server stuff). contact me here.


Comments and discussion about How to merge/concat two arrays together in JS?

Found this interesting? Maybe you want to read some more in this series?

Or see other topics in the JavaScript language

Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScript
Or see random questions

How to find an item by Primary Key in Eloquent, or throw a ModelNotFoundException exception if it isn't found?

What is the difference between empty(), isset(), != null, is_null() in PHP

How to find the 2nd most common item in an array?

How to prevent Eloquent from adding created_at or updated_at timestamps?

Why should you update APP_URL from from http://localhost?

Remove trailing slash (redirect to remove trailing slash) in .htaccess

How to disable file hotlinking in Apache with .htaccess

How do you access the php://input stream?

How to sort an array in javascript?

How to undelete a soft deleted Eloquent row?