Answers for "remove extra whitespaces in a string javascript"

3

remove extra space in string js

newString = string.replace(/\s+/g,' ').trim();
Posted by: Guest on May-28-2020
23

javascript remove all whitespaces

var spacesString= "Do I have spaces?"; 
var noSpacesString= myString.replace(/ /g,'');// "DoIhavespaces?"
Posted by: Guest on August-01-2019
6

js method string remove extra spaces

const sentence = '    My string with a    lot   of Whitespace.  '.replace(/\s+/g, ' ').trim()

// 'My string with a lot of Whitespace.'
Posted by: Guest on January-04-2021
0

remove whitespace with regex javascript

return str.replace(/\s/g, '');
Posted by: Guest on November-29-2020
0

remove extra spaces javascript

const removeExtraSpaces = (string) => {
  const newText = string
    .replace(/\s+/g, " ")
    .replace(/^\s+|\s+$/g, "")
    .replace(/ +(\W)/g, "$1");
  return newText
};
console.log(removeExtraSpaces("  Hello   World!"))
//Hello World!
Posted by: Guest on May-17-2022

Code answers related to "remove extra whitespaces in a string javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language