Something like this:
var s = " a b c ";
console.log(
s.replace(/\s+/g, ' ')
)
More Related Contents:
- Trim string in JavaScript?
- Trim specific character from a string
- How to trim() white spaces from a string?
- Regular expression to get a string between two strings in Javascript
- Regular Expression to get a string between parentheses in Javascript
- Insert a string at a specific index
- Is there a way to create a function from a string with javascript?
- Capitalize words in string [duplicate]
- Optimum way to compare strings in JavaScript? [duplicate]
- How to create streams from string in Node.Js?
- What does ${} (dollar sign and curly braces) mean in a string in JavaScript?
- How to insert variables in JavaScript strings?
- JavaScript replace() method dollar signs
- How can I use jQuery to style /parts/ of all instances of a specific word?
- Is there a JavaScript strcmp()?
- How can I insert new line/carriage returns into an element.textContent?
- Reversing a string in JavaScript
- What’s the point of new String(“x”) in JavaScript?
- How to remove part of a string?
- Javascript unicode string, chinese character but no punctuation
- Format a JavaScript string using placeholders and an object of substitutions?
- Remove occurrences of duplicate words in a string
- Convert string to datetime
- JavaScript adding a string to a number
- Extract the text out of HTML string using JavaScript
- What is the difference between ‘ and ” in JavaScript?
- String strip() for JavaScript? [duplicate]
- Print / display a JavaScript variable’s name instead of it’s value
- How to count the number of lines of a string in javascript
- Does jQuery strip some html elements from a string when using .html()?