日期:2014-05-16 浏览次数:20397 次
var arr=[[[[11,22],33],44],[55,66],77]; function loop(arr) { var result =""; for(var i = 0 ; i < arr.length ; i ++) { if(arr[i] instanceof Array) result += loop(arr[i]) else result += arr[i].toString()+"<br/>"; } return result; } document.write(loop(arr))
------解决方案--------------------
var arr = [[[[11,22],33],44],[55,66],77], arr2 = []; function cloneArray(target, source){ for(var i = 0, len = source.length; i < len; i++){ var el = source[i]; if(Object.prototype.toString.call(el) === "[object Array]"){ cloneArray(target, el); }else{ target.push(el); } } } cloneArray(arr2, arr); console.log(arr2);
------解决方案--------------------
<script>
var arr=[[[[11,22],33],44],[55,66],77];
var arr2=[];
var item = arr;
var str = "";
while(item.lenght == 2) {
str = str + item[1] + ",";
item = item[0];
}
str = str + item + ",";
arr2 = str.split(",");
alert(str);
</script>
将上面SCRIPT复制,运行, 得到结果 11,22,33,44,55,66,77,
细节方面,自己处理..
------解决方案--------------------
<script type="text/javascript"> var arr=[[[[11,22],33],44],[55,66],77]; var arr2=arr.join(',').split(','); alert(arr2); </script>