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 :: change firebase region 
Javascript :: append li to ul javascript 
Javascript :: bar chart height and with change in chart.js 
Javascript :: remove spaces and line breaks javascript 
Javascript :: js get timezone name 
Javascript :: button click redirection to another page vue 
Javascript :: random in range js 
Javascript :: javascript foreach key value 
Javascript :: jquery post json example 
Javascript :: UnhandledPromiseRejectionWarning: Error: Node is either not clickable or not an HTMLElement 
Javascript :: jquery remove option from select by value 
Javascript :: react ReferenceError: regeneratorRuntime is not defined 
Javascript :: remove word from string javascript 
Javascript :: converting binary to text js 
Javascript :: javascript async await for x seconds 
Javascript :: radio button checked event jquery 
Javascript :: discord.js wait seconds 
Javascript :: how to disable a div in javascript 
Javascript :: play an audio at a specific volume in javascript 
Javascript :: remove hidden attribute in js 
Javascript :: unsafe value used in a resource URL context 
Javascript :: jquery get class name 
Javascript :: create button inside td tag javascript 
Javascript :: adding delay in javascript foreach loop 
Javascript :: javascript queryselector data attribute 
Javascript :: ElevatedButton styling 
Javascript :: webview javascript enabled 
Javascript :: canvas draw image not blurry 
Javascript :: how to determin if element is in viewport with jquery 
Javascript :: index export in nodejs 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =