• 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:

  • Resize an iframe to fit its content
  • Combine two arrays using the spread operator
  • Check if an Item Exists in an Array
  • Find last n matches

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