有没有办法合并下面的数组:
var arr = [["2014-2-5", "2014-2-4", "2014-1-9", "2014-1-8"], [], ["2014-2-4"], [], []]让它看起来像这样:
["2014-2-5", "2014-2-4", "2014-1-9", "2014-1-8", "2014-2-4"]我尝试过console.log($.merge(arr ));,但它不起作用。
谢谢
发布于 2014-02-06 09:03:10
发布于 2014-02-06 09:55:22
不是合并而是扁平化-
Array.prototype.flatten= function(){
var A= [];
this.forEach(function(itm){
if(itm!= undefined){
if(!itm.flatten) A.push(itm);
else A= A.concat(itm.flatten());
}
});
return A;
}
var arr= [["2014-2-5", "2014-2-4", "2014-1-9",
"2014-1-8"], [], ["2014-2-4"], [], []];
arr.flatten();
// returned value: (Array)
['2014-2-5', '2014-2-4', '2014-1-9', '2014-1-8', '2014-2-4']https://stackoverflow.com/questions/21591760
复制相似问题