Similar to arrays, there are other string methods that you might want to know and use in the future. These methods are
trimRight(). The syntax and the function of each methods is shown below.
- returns the primitive value of the object string
- splits the string by
separatorand returns an array of strings, containing the separated parts
- separator can be a regular expression
- removes whitespace from the beginning and end of the string
- remove whitespace from the left/right side of the string
Let's take a look at the methods one by one. The
valueOf() method returns the primitive value of the string, which is essentially the same thing saying
split() method separates each word in
str2 by detecting the space bar and places each word into an element in the array. The
trimRight() methods simply remove the white spaces in the string and make it look cleaner when printed.