JavaScript Strings Object - Javascript Objects

What is JavaScript Strings Object?


In order to store a series of characters the String object is used. In other words, string is an array of characters. The JavaScript string can have primitive data type which again have some helper methods.

JavaScript have the ability to convert string primitives to string objects and vice versa. We can achieve this using any of the helper methods.


Syntax:
You can use the below syntax for creating a String object −

What are String Properties?

Below are the list of the properties of String object and their description.
Property
Description
constructor
It returns a reference to the String function that created the object.
length
It returns the length of the string.
prototype
The prototype property permits you to add methods and properties to an object.
The prototype property permits you to add methods and properties to an object.
In the upcoming sections, we will have a few examples which explains the use of String properties.

What are String Methods?

Below is the list of the methods available in String object along with their description.

Method
Description
charAt()
This method returns the character at the specified index.
charCodeAt()
This method gives a number indicating the Unicode value of the character at the given index.
concat()
This method combines the text of two strings and returns a new string.
indexOf()
This method returns the index within the calling String object of the first occurrence of the specified value, or -1 if not found.
lastindexOf()
This method returns the index within the calling String object of the last occurrence of the specified value, or -1 if not found.
localeCompare()
This method returns a number indicating whether a reference string comes before or after or is the same as the given string in sort order.
match()
This method is used to match a regular expression against a string.
replace()
This method is used to find a match between a regular expression and a string, and to replace the matched substring with a new substring.
search()
This method executes the search for a match between a regular expression and a specified string.
slice()
This method extracts a section of a string and returns a new string.
split()
This method splits a String object into an array of strings by separating the string into substrings.
substr()
This method returns the characters in a string beginning at the specified location through the specified number of characters.
substring()
This method returns the characters in a string between two indexes into the string.

toLocaleLowerCase()

By using this method the characters within a string are converted to lower case while respecting the current locale.
toLocaleUpperCase()
By using this method the characters within a string are converted to upper case while respecting the current locale.
toLowercase()
This method returns the calling string value converted to lower case.
toString()
This method returns a string representing the specified object.
toString()
This method returns the calling string value converted to uppercase.
valueOf()
This method returns the primitive value of the specified object.

What are String HTML Wrappers?

Below is a list of the methods that return a copy of the string wrapped inside ansuitable HTML tag.

Method
Description
anchor()
This method creates an HTML anchor that is used as a hypertext target.
big()
This method creates a string to be displayed in a big font as if it were in a <big> tag.
blink()
This method creates a string to blink as if it were in a <blink> tag.
bold()
This method creates a string to be displayed as bold as if it were in a <b> tag.
fixed()
This method creates a string to be displayed in fixed-pitch font as if it were in a <tt> tag
fontcolor()
This method causes a string to be displayed in the specified color as if it were in a <font color="color"> tag.
fontsize()
This method causes a string to be displayed in the specified font size as if it were in a <font size="size"> tag.
italics()
This method causes a string to be italic, as if it were in an <i> tag.
link()
This method createsan HTML hypertext link that requests another URL.
small()
This method causes a string to be displayed in a small font, as if it were in a <small> tag.
strike()
This method causes a string to be displayed as struck-out text, as if it were in a <strike> tag.
sub()
This method causes a string to be displayed as a subscript, as if it were in a <sub> tag
sup()
This method causes a string to be displayed as a superscript, as if it were in a <sup> tag
In the upcoming sections, we will have a few examples which explains the use of String methods.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Javascript Objects Topics