标签:array isarray 数组 log turn each set war bsp
function flattening(arr = []) { let newArr = []; arr.forEach(item => { if (Array.isArray(item)) { newArr.push(...flattening(item)); } else { newArr.push(item); } }); return [...new Set(newArr)]; } let a = [1, ‘ok‘, ‘ok‘, 2, [3, 4], [[[[[5, 6], 7]], 8], 1, 2, 3, 3]]; console.log(flattening(a)); // => [1, "ok", 2, 3, 4, 5, 6, 7, 8]
标签:array isarray 数组 log turn each set war bsp
原文地址:https://www.cnblogs.com/coderDemo/p/13356722.html