remove blank space javascript code example

Example 1: js remove space from string

string.split(" ").join("")

Example 2: remove blank space javascript

str.replaceAll(/\s/g,'')

.replace(/ /g,'')

Example 3: javascript remove space from string

const removeSpaces = str => str.replace(/\s/g, '');

// Example
removeSpaces('hel lo wor ld');      // 'helloworld'

Example 4: remove space from string javascript

var str = "       Hello World!        ";
alert(str.trim());

Example 5: how to remove empty spaces befiore string js

const greeting = '   Hello world!   ';

console.log(greeting);
// expected output: "   Hello world!   ";

console.log(greeting.trim());
//your boy siddhesh Kuakde

Tags:

Misc Example