不使用generator函数,是嵌套数组扁平化
var arr = [1, [[2, 3,[8,9,[6,5,4,6,4],10]], 4], [5, 6]]; var arr2 = []; function flat(arr){ for( let i = 0 ; i < arr.length; i ++){ typeof arr[i] !== 'number' ?flat(arr[i]):arr2.push(arr[i]) } } flat(arr); console.log(arr2);