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"];
  3.  
  4. console.log(first_array.concat(second_array));

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

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



More...


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 merge/concat two arrays together in JS?

How to select all rows for a certain month (or day, year or time), using Eloquent

How to use subdomains as parameters in your routes (or in your web.php file)

How to make Apache force download of files (in .htaccess)

How to group a SQL statement in brackets/parenthesis

How to Force www or non-www in htaccess

How to fix the MySQL related "Specified key was too long error" error in Laravel

Push vs Pop vs Shift vs Unshift

How to hide certain file types from directory listings

How to see all of the options for an artisan command?