2018-6-21_《ES6数组扁平化函数》
const flattenArray = arr => { const flattened = [].concat(...arr); return flattened.some(v => Array.isArray(v))?flattenArray(flattened):flattened; } const arr = [1,[2,3,[3.1,3.2]],4]; console.log(flattenArray(arr)); //[1, 2, 3, 3.1, 3.2, 4]
前端-语言