The basic method for merging arrays in JavaScript is described.

Source: Internet
Author: User

The basic method for merging arrays in JavaScript is described.

Here are two simple methods:
First

var mergeTo = [4,5,6],    mergeFrom = [7,8,9];  mergeTo = mergeTo.concat(mergeFrom); mergeTo; // is: [4, 5, 6, 7, 8, 9] 

Or

var a = [1,2], b = [3,4], c = a.concat(b);  


Second

var mergeTo = [4,5,6], var mergeFrom = [7,8,9];  Array.prototype.push.apply(mergeTo, mergeFrom);  mergeTo; // is: [4, 5, 6, 7, 8, 9] 

Merge multiple arrays merge array:

// Special processing service-you must enable var _ SPECIAL_MUST_ENABLE_LIST = ['intime']; if (termNo! = Null & termNo. indexOf ("9966") = 0) {var newMustEnableList = ['mobile', 'psp ', 'jtk', 'credentials', 'train', 'bank ', 'alipay', 'lottery', 'movi', 'littletransfer', 'trafficfines', 'certificate', 'mall', 'airplane ', 'Hotel ', 'recycle']; _ SPECIAL_MUST_ENABLE_LIST = _ SPECIAL_MUST_ENABLE_LIST.concat (newMustEnableList );}

Articles you may be interested in:
  • JavaScript simulated array merging concat
  • JS implements the method of merging two arrays and removing duplicate items and leaving only one
  • Difference between JS array merge push and concat
  • Examples of array merging and sorting in JavaScript
  • JavaScript merge two arrays and remove repeated items
  • Examples of merging multiple arrays using native JavaScript
  • Comparison of several methods and advantages of JS array Merging
  • Use different methods to combine/merge two JS Arrays
  • N methods for merging arrays in JavaScript
  • JavaScript and jquey Merge multiple arrays

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.