function flatten(arr) {
        return arr.reduce(function (flat, toFlatten) {
          return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
        }, []);
      }
      

      Javascript language logo
      Flatten array

      My JavaScript recipes

      Flatten an array

      Shortcut: array.flatten

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.