• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details
Home / Miscellaneous / Merge two or more arrays together

Merge two or more arrays together

Merge two or more arrays together

Call concat() on the first array, and pass each array to merge with it in as arguments. It returns a new array.

var sandwiches1 = ['turkey', 'tuna', 'blt'];
var sandwiches2 = ['chicken', 'pb&j'];
var allSandwiches = sandwiches1.concat(sandwiches2);

// logs ['turkey', 'tuna', 'blt', 'chicken', 'pb&j']
console.log(allSandwiches);

Source

https://vanillajstoolkit.com/reference/arrays/array-concat/

Miscellaneous

Related Snippets:

  • Remove falsy values from an array
  • Get and set the text of an element (without markup)
  • Get all direct descendant elements that match a test
  • Remove Duplicates From an Array

Primary Sidebar

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2025 JavaScriptSource.com

  • About
  • Privacy Policy
  • FAQ
  • Jobs For Developers