Home > Web Front-end > JS Tutorial > Explanation of the basic methods of merging arrays in JavaScript_Basic knowledge

Explanation of the basic methods of merging arrays in JavaScript_Basic knowledge

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 15:11:38
Original
1405 people have browsed it

Here are two simple methods:
The first type

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

or

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


The second type

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

Merge multiple arrays merge array:

// 特殊处理业务-必须启用 
var _SPECIAL_MUST_ENABLE_LIST = ['intime']; 
 
if(termNo != null && termNo.indexOf("9966") == 0){ 
  var newMustEnableList = ['mobile','psp','jtk','credit','train','bank','alipay','lottery','movie','littleTransfer', 
               'trafficFines','concert','mall','airplane','hotel','recycle']; 
  _SPECIAL_MUST_ENABLE_LIST = _SPECIAL_MUST_ENABLE_LIST.concat(newMustEnableList); 
} 
Copy after login

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template