javascript – How to remove whitespace in a string?

Question:

How can I remove whitespace in a string? How can I put all the characters together and remove those spaces?

var incognita = "Hola como estas";

Answer:

You can use String.replace () like this:

 var incognita = "Hola como estas" console.log(incognita.replace(/ /g, ""));
Scroll to Top