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 :: read directory in node js 
Javascript :: add url query in js 
Javascript :: javascript get current month start and end date 
Javascript :: javascript screen size 
Javascript :: javascript get element height and width 
Javascript :: check if a date time string is a valid date in js 
Javascript :: jquery set href of link 
Javascript :: get text of selected option jquery 
Javascript :: alphabets regex js 
Javascript :: cypress backspace 
Javascript :: node js remove html tags from string 
Javascript :: how to use jquery in chrome dev tools 
Javascript :: just number regex 
Javascript :: disable anchor tag jquery after click 
Javascript :: install moment in goole dev console 
Javascript :: leaflet.js cdn 
Javascript :: javascript padstart 
Javascript :: __WEBPACK_IMPORTED_MODULE_0_react___default.a.createContext is not a function 
Javascript :: unique objects in array javascript 
Javascript :: javascript document load 
Javascript :: devextreme datagrid get selected row keys 
Javascript :: convert english number to bangla in javascript 
Javascript :: jquery remove br from div 
Javascript :: update node js ubuntu 
Javascript :: settimeout node js 
Javascript :: play background music in html jasvascript 
Javascript :: how to get the first character of a string in javascript 
Javascript :: gradlew clean in react native 
Javascript :: javascript setinterval 
Javascript :: wp_enqueue_script bootstrap 5 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =