1. Using Array. IsArray ()

    let arr = [];
    function flat(arrA){
      for(let item of arrA){
        if(Array.isArray(item)){
          flat(item);
        }else{ arr.push(item); }}}let arrB = [1.2[3].4[5[6.7]]];
   console.log(arr);
   / /,2,3,4,5,6,7 [1]
Copy the code

2. The ES6 Flat method

let arr = [2.3[4.5], [6[7[8]]]]];
console.log(arr.flat(Infinity));
/ /,3,4,5,6,7,8 [2]
Copy the code

Flat is the number of dimensions of the array, and if you don’t know how many dimensions the array is, you can set it to Infinity.