Table of Contents
This guide covers string object in JavaScript with practical context and easy-to-follow details. Use it to understand the subject and apply the information confidently.
When JavaScript automatically changes between the original string and String objects, you can call any help method of the String object on an original string.
Syntax
Use the following syntax to create a String object:
var val = new String ( string );
The String Parameter is a sequence of characters that has been correctly encoded.
Properties of String
Below is a list of properties of the String object and its description.
Properties Description
Constructor
Returns a reference to the String function that creates that object
Length
Returns the length of the string
Prototype
The prototype property allows you to add properties and methods to an object.
Methods of String
Below is a list of available methods in the String object with its description.
Method Description
CharAt ()
Returns the character at the index (index) specified
CharCodeAt ()
Returns a number indicating the Unicode value of the character in the given index
Concat ()
Match the text of the two strings and return a new string
IndexOf ()
Returns the index in the String object calling the first occurrence of the specified value, or -1 if not found
LastIndexOf ()
Returns the index in the String object calling of the last occurrence of the specified value, or -1 if not found
LocaleCompare ()
Returns an indication whether or not a string refers to before or after, or is the same as the given string in the sort order
Match ()
Used to match a Regular Expression with a string
Replace ()
Used to find a match between a given Regular Expression and a string, and to replace a substring that matches a new substring.
Search ()
Execute the search for a match between a regular expression and a specified string
Slice ()
Extract an area of a string and return a new string
Split ()
Divide a String object into an array of strings by dividing the string into sub-strings
Substr ()
Returns the characters in a string starting at the specified position with a specified number of characters
Substring ()
Returns characters in a string between two indexes within the string
ToLocaleLowerCase ()
The characters inside a string are converted into lowercase while respecting the current Locale
ToLocaleUpperCase ()
The characters inside a string are transformed into floral typefaces while respecting the current Locale
ToLowerCase ()
Returns the value of the calling string being converted to lower case
ToString ()
Returns a string representing the specified object
ToUpperCase ()
Returns the value of the calling string being converted to uppercase
ValueOf ()
Returns the original value of the specified object
String HTML Wrappers
Below is a list of methods that return a copy of the string wrapped within an appropriate HTML tag.
Method Description
Anchor ()
Create an Anchor HTML that is used as a hypertext target (hypertext target)
Big ()
Create a string to be displayed in a big font as if it were in a tag
Blink ()
Create a flashing sequence as if it were in a card
Bold ()
Create a string to be displayed in bold form as if it were in a tag
Fixed ()
Create a string to be displayed in a fixed font as if it were in a tag
Fontcolor ()
Create a string to be displayed in a fixed color as if it were in a tag
Fontsize ()
Making a string is displayed in a font size defined as when it is in a tag
Italics ()
Make a string in italic format as if it were in a card
Link ()
Create an HTML hypertext link that requires another URL
Small ()
Make a string displayed in Small font format as if it were in a tag
Strike ()
Make a string displayed in the form of dashed text as if it were in a tag
Sub ()
Make a string displayed in the form of the lower index as if it were in a tag
Sup ()
Make a string displayed in the form of the upper index as if it were in a tag
According to Tutorialspoint
Previous article: Boolean object in JavaScript
Next post: Array (Array) in JavaScript
FAQ
What should I check before following these steps?
Confirm device and software compatibility, save important data, and make sure you have the required permissions, files, and account access.
Why might the process not work?
Common causes include outdated software, missing permissions, incompatible hardware, an unstable connection, or completing a step in the wrong order.
Can I undo the changes if necessary?
That depends on the tool or setting. Use built-in restore options when available, keep a backup, and record the original configuration first.
Reader Comments 0
Sign in with email or Google to join the discussion.