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

Complete steps to quickly build a vue3.0 project

Table of contents 1. We must ensure that the vue/...

Basic steps to use Mysql SSH tunnel connection

Preface For security reasons, the root user of My...

Design theory: Why are we looking in the wrong place?

I took the bus to work a few days ago. Based on m...

Example of using Nginx to implement port forwarding TCP proxy

Table of contents Demand Background Why use Nginx...

How to uninstall Linux's native openjdk and install sun jdk

See: https://www.jb51.net/article/112612.htm Chec...

MySQL 5.7.17 installation and configuration method graphic tutorial

This article shares the installation and configur...

Solution to the problem "Table mysql.plugin doesn't exist" when deploying MySQL

Today I deployed the free-installation version of...

Detailed installation and configuration tutorial of PostgreSQL 11 under CentOS7

1. Official website address The official website ...

HTML form and the use of form internal tags

Copy code The code is as follows: <html> &l...

MySQL 5.7.23 decompression version installation tutorial with pictures and text

Download the MySQL installer Official download ad...

Detailed explanation of the two modes of Router routing in Vue: hash and history

hash mode (default) Working principle: Monitor th...

Implementation of Docker container state conversion

A docker container state transition diagram Secon...

Three ways to implement virtual hosts under Linux7

1. Same IP address, different port numbers Virtua...