I wanted to find the built-in function for this to no avail so I had to write it in script:
function squeeze(range) {
return [].concat(...range).filter(n => n)
}
This JS function flattens the 2D array range
and returns it.
Note that it filters out empty cells with uneven columns.
While not officially documented (yet), flatten() also exists as a built-in formula. See here for more info.
UPDATE: Since the end of 2020 the function is now documented. See here for more info.