标签:
递归
var result=[]; var arr=[1, [2, [ [3, 4], 5], 6]]; function flat(arr,result){ for(var i=0;i<arr.length;i++){ if(typeof arr[i]==="number"){ result.push(arr[i]); } else{ flat(arr[i],result); } } } flat(arr,result); console.log(result);
标签:
原文地址:http://www.cnblogs.com/dll-ft/p/5854235.html