The String object helps you work with a series of characters; It helps handle the original string data types in JavaScript with some help methods.

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

4 ★ | 1 Vote | 👨 194 Views

Above is an article about: "String object in JavaScript". Hope this article is useful to you. Don't forget to rate the article, like and share this article with your friends and relatives. Good luck!

« PREV POST
NEXT POST »