//使用concat的 function init (arr) { var newArr = []; if (arr instanceof Array) { arr.forEach(function (value) { newArr = newArr.concat(init(value)); }); } else { newArr.push(arr); } return newArr; } init([1, [2], [3, [[4]]]]); //不使用concat的 [1, {}, [3, [[4]]]].toString().split(',').map(v => { switch(v) { case '[object Object]': return {}; default: { const isNumberString = v => v && !isNaN(v); if(isNumberString(v)) return Number(v); else return v; } } }).filter((v) => !Object.is(v, '')) //[1,[2],[3],[4],[5,[6]]].toString() == "1,2,3,4,5,6"
|
近期评论