You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
function flattenDeep(arr, result = []) {
var len = arr.length
for(var i = 0; i < len; i++) {
if(Array.isArray(arr[i])) {
flattenDeep(arr[i], result)
}else {
result.push(arr[i])
}
}
return result
}
Activity
nusr commentedon Jun 15, 2019
forever-z-133 commentedon Jun 15, 2019
Delicate-lee commentedon Jun 15, 2019
function fn(arr) {
let res = [];
(function gn(arr) {
arr.forEach(item => {
if(Array.isArray(item)) {
gn(item)
} else res.push(item)
})
})(arr)
return res
}
tannnb commentedon Jun 16, 2019
function flattenDeep(arr) {
if(arr && arr.length == 0) {
return arr
}
return arr.toString().split(',')
}
flattenDeep([1,2,3,[4,[5,[6]]]]) // ["1", "2", "3", "4", "5", "6"]
arronf2e commentedon Jun 18, 2019
HuaRongSAO commentedon Jun 21, 2019
基础数据:arr.toString().split(",");
复杂数据:const flatten = arr => [].concat(... arr.map(ar => Array.isArray(ar)?flatten(arr): ar)
luobinhang commentedon Jun 25, 2019
HuaRongSAO commentedon Jun 25, 2019
MY729 commentedon Jul 2, 2019
数组扁平化多种方法实现
Konata9 commentedon Jul 8, 2019
shufangyi commentedon Jul 23, 2019
chenyouf1996 commentedon Jul 26, 2019
ppppp-x-x commentedon Jul 30, 2019
jiamianmao commentedon Aug 8, 2019
const flat = arr => arr.toString().split(',')
8 remaining items