Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

remove extra space in string js

newString = string.replace(/s+/g,' ').trim();
Comment

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.'
Comment

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!
Comment

PREVIOUS NEXT
Code Example
Javascript :: How find a specific character in js 
Javascript :: your mom is your dad 
Javascript :: node mon in loopback 
Javascript :: ajaxcall 
Javascript :: create text editor with react-redux 
Javascript :: delete attribute javascript 
Javascript :: javascript ascii to hex 
Javascript :: jquery datepicker set year range 
Javascript :: image url to file js 
Javascript :: javaScript getSeconds() Method 
Javascript :: react onclick new tab 
Javascript :: find difference in array of objects javascript 
Javascript :: react map 
Javascript :: stringify 
Javascript :: outsystems close feedback message 
Javascript :: @jsonignore unrecognized field 
Javascript :: javascript save result to file 
Javascript :: faker npm 
Javascript :: javascript autoplay audio 
Javascript :: js check if string is base64 
Javascript :: or in js 
Javascript :: downgrade react version to 17 
Javascript :: node js get file name without extension 
Javascript :: jquery ajax delete 
Javascript :: Javascript - check if div contains a word? - Stack Overflow 
Javascript :: adminlte 3 toasts 
Javascript :: javascript is variable number or string 
Javascript :: how to check if a string is correctly encoded as base64 in javascript 
Javascript :: angular An accessor cannot be declared in an ambient context. 
Javascript :: placeholder in angular 9 select with working required 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =