JavaScript string
Strings are useful for holding data that can be represented in text form . A string literal is zero or more characters enclosed in single or double quotation marks. Variable whose value is a string primitive , formed by assigning a string literal, another string variable, or a string expression. A String object is created by using the new Operator , and has a data type of Object.JavaScript String Operations
String length property
JavaScript String length property return the number of characters in a string.
Return: 5
charAt(index)
charAt() is a method that returns the character from the specified index.
Return: A and D
localeCompare()
The localeCompare() method returns a number indicating whether a reference string comes before or after or is the same as the given string in sort order.Return Value
- 0 - If the two strings are equal
- 1 - no match, When the referenceStr occurs after compareStr
- -1 - no match,When the referenceStr occurs before compareStr
Return: -1
toLowerCase()
Convert string str to lower case.
Return: abcd efgh
toUpperCase()
Convert string str to upper case.
Return : ABCD EFGH
indexOf(substr)
Returns the position of the first occurrence of a specified value in a string.
Return: 11
split(separator)
Splits a string between string separators.
Return: JavaScript,Split(),Test
trim()
Trim whitespace from beginning and end of string str.
Return: JavaScript Trim
startsWith(str)
This method returns true if the string begins with the characters, and false if not.
Return : true
concat(str)
The concat() method is used to join two or more strings.
Return: JavaScript Tutorial
substr(start, length)
This method returns the characters in a string beginning at the specified location through the specified number of characters.
Return : substring
replace(regexp, str)
The replace() method returns a new string with some or all matches of a pattern replaced by a replacement. The pattern can be a string or a RegExp , and the replacement can be a string or a function to be called for each match.Return: JavaScript replace method
str.search(regexp)
Gets the index of the first occurrence of a substring and returns the position of the match.. This method returns -1 if no match is found. The search value can be string or a regular expression.Return : 11
toString (String )
Return the string representation of a String object.
Return : 100