ES10 - String Trim methods

This tutorial covers String Trim methods trimStart and trimEnd introduced ES2019 with examples..

ES10 String - trimStart,trimEnd methods

ES10 introduced two methods to String class to latest javascript. These two string methods to remove empty space from a given string

  • String.trimStart() - removes the whitespaces from starting position of a given string
  • String.trimEnd() - removes the whitespaces from end position of a input string

Here is an example

let str1=" firstString";
let str2="secondString ";

str1.length // outputs 13
str1.trimStart(); // outputs firstString without space
str1.length // outputs 12

str2.length // outputs 13
str2.trimEnd(); // outputs secondString without space
str2.length // outputs 12