标签:
多维数组转一维数组:[1,[2,3]] ==》 [1,2,3]
function tran(array){
if(Object.prototype.toString.call(array) != ‘[object Array]‘){
alert(Object.prototype.toString.call(array) + "非数组")
return ;
}
var newArr = [];
function trans(arr){
for (var num = 0; num < arr.length;num ++){
if(arr[num].length){
trans(arr[num]);
} else {
newArr.push(arr[num]);
}
}
}
trans(array);
return newArr;
}
typeof
http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.4.2
参考:http://my.oschina.net/sfm/blog/33197,http://blog.csdn.net/spy19881201/article/details/12192767,http://www.cnblogs.com/Aralic/p/4397015.html
标签:
原文地址:http://www.cnblogs.com/yunkong/p/4399037.html