3 Ways to Merge Arrays in JavaScript

3 Ways to Merge Arrays in JavaScript

In this tutorial, we'll learn 3 ways to merge arrays in JavaScript using spread operator, array.concat() and array.push().

An array is a data structure representing an ordered collection of indexed items.

A common operation performed on multiple arrays is merge — when 2 or more arrays are merged to form a bigger array containing all the items of the merged arrays.

For example, having two arrays [1, 2] and [5, 6], then merging these arrays results in [1, 2, 5, 6].

In this post, you’ll find 3 ways to merge arrays in JavaScript: 2 immutable (a new array is created after the merge) and 1 mutable (items are merged into an array).

  1. Immutable merge of arrays
  • Merge using the spread operator
  • Merge using array.concat() method
  1. Mutable merge of arrays
  • Merge using array.push() method

javascript array

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Fill and Filter in Array in JavaScript

By the word Array methods, I mean the inbuilt array functions, which might be helpful for us in so many ways. So why not just explore and make use of them, to boost our productivity. Let’s see them together one by one with some amazing examples.

Javascript Array From Example | Array.prototype.from()

Javascript array from() is an inbuilt function that creates a new, shallow-copied array instance from an array-like object or iterable object.

A quick guide to JavaScript Arrays

6 most commonly used methods and how they’re implemented. Arrays are a structure common to all programming languages so knowing what they are and having a firm grasp on what you’re able to accomplish with Arrays will take you a long way in your journey as a software developer.

Javascript Array Shift Example | Array.prototype.shift()

Javascript array shift() is an inbuilt function that removes the first item from an array and returns that deleted item. It changes the length of the array.

Javascript Array Keys Example | Array Keys In Javascript

Javascript Array keys() method returns the new array Iterator object that contains the keys for each index in an array. avascript Array Keys Example.