javascript function that removes whitespace from the beginning and end of a string code example
Example 1: 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());
console.log(stringWithSpaces.trimEnd());
console.log(stringWithSpaces.trim());
Example 2: how to remove whitespace only from first position of string js
function ltrim(str) {
if(!str) return str;
return str.replace(/^\s+/g, '');
}