JavaScript array merging case study

JavaScript array merging case study

Method 1:

var a = [1,2,3];
var b=[4,5]
a = a.concat(b);
console.log(a);
//The output here is [1, 2, 3, 4, 5]

Method 2:

// ES5 notation var arr1 = [0, 1, 2];
var arr2 = [3, 4, 5];
Array.prototype.push.apply(arr1, arr2);
console.log(arr1) // [0, 1, 2, 3, 4, 5]

Method 3:

// ES6 way var arr1 = [0, 1, 2];
var arr2 = [3, 4, 5];
arr1.push(...arr2);
console.log(arr1) // [0, 1, 2, 3, 4, 5]
// ES6 way var arr1 = [0, 1, 2];
var arr2 = [3, 4, 5];
var arr3=[...arr1, ...arr2]
console.log(arr3) // [0, 1, 2, 3, 4, 5]

This is the end of this article about JavaScript array merging cases. For more relevant JavaScript array merging content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Commonly used JavaScript array methods
  • JavaScript Array Detailed Summary
  • Common array operations in JavaScript
  • JavaScript Array Methods - Systematic Summary and Detailed Explanation
  • Summary of examples of common methods of JavaScript arrays
  • JS uses map to integrate double arrays
  • Detailed explanation of built-in methods of javascript array

<<:  Advanced and summary of commonly used sql statements in MySQL database

>>:  Practical way to build selenium grid distributed environment with docker

Recommend

The principle and application of ES6 deconstruction assignment

Table of contents Array destructuring assignment ...

JavaScript function call, apply and bind method case study

Summarize 1. Similarities Both can change the int...

Analysis of the use and principle of Docker Swarm cluster management

Swarm Cluster Management Introduction Docker Swar...

Solve the problem of Docker starting Elasticsearch7.x and reporting an error

Using the Docker run command docker run -d -p 920...

How to change the domestic source of Ubuntu 20.04 apt

UPD 2020.2.26 Currently Ubuntu 20.04 LTS has not ...

Summary of some common writing methods that cause MySQL index failure

Preface Recently, I have been busy dealing with s...

vitrualBox+ubuntu16.04 install python3.6 latest tutorial and detailed steps

Because I need to use Ubuntu+Python 3.6 version t...

JavaScript implements changing the color of a web page through a slider

Hello everyone, today when I was looking at the H...

Remote development with VSCode and SSH

0. Why do we need remote development? When develo...

Summary of changes in the use of axios in vue3 study notes

Table of contents 1. Basic use of axio 2. How to ...

Node and Python two-way communication implementation code

Table of contents Process Communication Bidirecti...

How to deploy code-server using docker

Pull the image # docker pull codercom/code-server...

How to implement responsiveness in Vue source code learning

Table of contents Preface 1. Key Elements of a Re...