Answers for "remove whitespace from beginning and end of string javascript"

3

javascript remove spaces at the beginning of the end of the string

const stringWithSpaces = '   I learn JS with Coderslang every day   ';

console.log(stringWithSpaces.trimStart());  //'I learn JS with Coderslang every day   '
console.log(stringWithSpaces.trimEnd());    //'   I learn JS with Coderslang every day'
console.log(stringWithSpaces.trim());       //'I learn JS with Coderslang every day'
Posted by: Guest on February-03-2021
0

javascript remove first space in string

//use trim() on your string. It removes first and last whitepsaces

let str = " aa bb    ";
console.log(str.trim()); // "aa bb"
Posted by: Guest on August-20-2020
0

how to remove whitespace only from first position of string js

function ltrim(str) {
  if(!str) return str;
  return str.replace(/^\s+/g, '');
}
Posted by: Guest on February-03-2021

Code answers related to "remove whitespace from beginning and end of string javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language