String Properties and Methods
There are also several methods that can be used to manipulate strings. Some of the most commonly used string methods are listed below:
concat(): This method concatenates (joins) two or more strings and returns a new joined string.
split(): This method splits a string into an array of substrings and returns the new array.
substr(): This method extracts parts of a string and returns the extracted part in a new string.
toLowerCase(): This function converts any uppercase letters in a string to lowercase and returns the new all-lowercase string..
toUpperCase(): This function changes all lowercase letters in a string to uppercase and returns the new uppercase version.
indexOf(): This method returns the index within a string at which a specified value first occurs, or -1 if it does not occur.
For example, the .concat() method can be used to add two strings together. When this method is called on a string, it returns a new string that is the result of concatenating the two strings. The original string is not modified.
For example, the character code for “A” is 65, and the character code for “a” is 97. Comparing two strings using the comparison operators will result in a Boolean value (true or false).
A value of -0 indicates that the two strings are equal, a value of less than 0 indicates that the first string comes before the second string in alphabetical order, and a value of greater than 0 indicates that the first string comes after the second string in alphabetical order.