WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

JavaScript String Reference


JavaScript Strings

A JavaScript string stores a progression of characters like "John Doe".

A string can be any content inside twofold or single quotes:

var carname = "Volvo XC60";
var carname = 'Volvo XC60';

String records are zero-based: The primary character is in position 0, the second in 1, thus on.


String Properties and Methods

Primitive qualities, as "John Doe", can't have properties or on the other hand techniques (since they are not objects).

But with JavaScript, strategies and properties are additionally accessible to crude qualities, on the grounds that JavaScript treats crude qualities as articles when executing strategies and properties.


String Properties

Property Description
constructor Returns the string's constructor function
length Returns the length of a string
prototype Allows you to add properties and techniques to an object

String Methods

Method Description
charAt() Returns the character at the predefined record (position)
charCodeAt() Returns the Unicode of the character at the predefined index
concat() Joins at least two strings, and returns another joined strings
endsWith() Checks whether a string closes with determined string/characters
fromCharCode() Converts Unicode qualities to characters
includes() Checks whether a string contains the predefined string/characters
indexOf() Returns the situation of the principal discovered event of a predefined esteem in a string
lastIndexOf() Returns the situation of the last discovered event of a predetermined esteem in a string
localeCompare() Compares two strings in the current locale
match() Searches a string for a match against an ordinary articulation, and returns the matches
repeat() Returns another string with a predefined number of duplicates of a current string
replace() Searches a string for a predefined esteem, or a normal articulation, and restores another string where the predefined values are replaced
search() Searches a string for a predetermined esteem, or normal articulation, and restores the situation of the match
slice() Extracts a piece of a string and returns another string
split() Splits a string into a variety of substrings
startsWith() Checks whether a string starts with indicated characters
substr() Extracts the characters from a string, starting at a predetermined begin position, and through the predetermined number of character
substring() Extracts the characters from a string, between two indicated indices
toLocaleLowerCase() Converts a string to lowercase letters, as indicated by the host's locale
toLocaleUpperCase() Converts a string to capitalized letters, as indicated by the host's locale
toLowerCase() Converts a string to lowercase letters
toString() Returns the estimation of a String object
Converts a string to capitalized letters
trim() Removes whitespace from the two finishes of a string
valueOf() Returns the crude estimation of a String object

String HTML Wrapper Methods

The HTML wrapper strategies return the string wrapped inside the proper HTML tag.

These are not standard strategies, and may not function as expected in all browsers.

Method Description
anchor() Creates an anchor
big() Displays a string utilizing a major font
blink() Displays a squinting string
bold() Displays a string in bold
fixed() Displays a string utilizing a fixed-pitch font
fontcolor() Displays a string utilizing a predetermined color
fontsize() Displays a string utilizing a predetermined size
Displays a string in italic
link() Displays a string as a hyperlink
small() Displays a string utilizing a little font
strike() Displays a string with a strikethrough
sub() Displays a string as subscript text
sup() Displays a string as superscript text