Google Sheets Function: TRIM
The TRIM function removes unnecessary spaces at the beginning and end of a string, as well as double spaces within the string.
Usage:
=TRIM(text)
Example of Use
The TRIM function here should remove all unnecessary spaces from the cell to its left:
=TRIM(A2)

Then drag down:

The unnecessary spaces have been successfully removed.