The recursive approach is concise but there is the concern of overflowing the call stack. That can be solved with a generator.
An iterative approach is also good to know
We loop through the array with a while loop and we take out an item from the array one at a time to check to see if that item is an array. If the item is not an array, we put it into the res array. If it is an array, we use a spread operator ... to get all the items out of it and put them back to the array. using Array.prototype.some