ES6的数组some:循环如果有一个满足条件则返回true
https://developer.mozilla.org...

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        console.log(flat([1,2,[3,4,[5]]]));
        function flat(arr){
            var isDeep=arr.some(item=>item instanceof Array);
            if(!isDeep){
                return arr;
            }
            var res=Array.prototype.concat.apply([],arr);
            return flat(res);
        }
    </script>
</body>
</html>

kangting
62 声望3 粉丝

一只小小的前端