changing double space to single in java script

Java
string.split(" ").join("")
Source

Also in Java: