Question - How can we replace multiple spaces with a single space?
Answer -
We can cover tabs, newlines by using the following code:
string = string.replace(/\s\s+/g, ' ');
We can cover only spaces by using the following code:
string = string.replace(/ +/g, ' ');