1. [代码] [JavaScript]代码 var source = [1, ['a', 'b'], [2, ['c' ,'d']]];function test(arr){var result = [];for(var i=0, len = arr.length;ilen;i++){if(Array.isArray(arr[i])){result = result.concat(test(arr[i]));}else{result.push(arr[i])
1. [代码][JavaScript]代码
var source = [1, ['a', 'b'], [2, ['c' ,'d']]]; function test(arr){ var result = []; for(var i=0, len = arr.length;i<len;i++){ if(Array.isArray(arr[i])){ result = result.concat(test(arr[i])); }else{ result.push(arr[i]); } } return result; } console.log(test(source));