JavaScript中将数组进行合并的基本方法讲解
程序员文章站
2024-01-04 13:48:58
这里简单地讲两种方法:
第一种
var mergeto = [4,5,6],
mergefrom = [7,8,9];...
这里简单地讲两种方法:
第一种
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); }
推荐阅读