How do I trim a string in JavaScript? That is, how do I remove all whitespace from the beginning and the end of the string in JavaScript?
I know this question has been asked three years back.Now,String.trim() was added natively in JavaScript.For an instance, you can trim directly as following,
String.trim()
document.getElementById("id").value.trim();