👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
The JavaScript trim () method removes white space from the start and end of a string. The trimLeft () and trimStart () methods cut white space at the start of a string. trimRight () and trimEnd () strip out blanks at the end of a string.
You can remove spaces, such as spaces, tabs, or newlines, at the start or end of a string. For example, suppose you have a string of customer names. You may want to make sure that there are no extra spaces at the end of each name.
This is where the trim () JavaScript function comes in. trim ()
removes the function of character spaces at the start and end of a string There are functions related to the plate () you can use:.
- TrimLeft ()
- TrimStart ()
- TrimRight ()
- TrimEnd ()
In this tutorial, we’ll explore the JavaScript trim () function and how it works. We’ll also look at the four related functions that you can use in place of or in addition to trim ().
JavaScript trim () String
The JavaScript trim () method removes white space from the start and end of a string. The trim () method creates a new string. trim () takes no arguments. This method is added at the end of a string.
Here is the syntax of the trim () method:
removes all spaces from the beginning and end of our string. There are only spaces at the end of our string, this are the only characters removed. trim () returns a new string. JavaScript strings are immutable, so they cannot be changed.