DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> JavaScript基礎知識 >> JavaScript中將數組進行合並的基本方法講解
JavaScript中將數組進行合並的基本方法講解
編輯:JavaScript基礎知識     

這裡簡單地講兩種方法:
第一種  

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); 
 

 
第二種 

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 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); 
} 

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved