Saturday, February 29, 2020

JavaScript String Object - Find out the different properties and methods of a JavaScript String object in this in-depth tutorial


Hello guys! good morning to you all and welcome to my new tutorial on JavaScript. In my previous tutorial i talked about exploring JavaScript Boolean methods with simple and clear examples.

Like i told you guys in the previous tutorial we had, we are going to be discussing about JavaScript Strings Object in this tutorial post. Like i always say, feel free to ask your questions via the comment box below or you can use the chat box for those reading through a desktop or a laptop. 

The String object lets you work with a series of characters; it wraps JavaScript's string primitive data type with a number of helper methods.

As JavaScript automatically converts between string primitives and String objects, you can call any of the helper methods of the String object on a string primitive.

Syntax

Below is the syntax that can be used to create a String object -

var val = new  String(string);

The String parameter is a series of characters that has been properly encoded.

You can also read our tutorial post on: Html - Text Links


String Properties

Below is a list of the properties of String object and their description.

Sr.No.Property & Description
1constructor
Returns a reference to the String function that created the object.
2length
Returns the length of the string.
3prototype
The prototype property allows you to add properties and methods to an object.
In the up coming tutorials, we will have a few examples to illustrate how JavaScript String properties can be used.

String Methods

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

Sr.No.Method & Description
1charAt()
Returns the character at the specified index.
2charCodeAt()
Returns a number indicating the Unicode value of the character at the given index.
3concat()
Combines the text of two strings and returns a new string.
4indexOf()
Returns the index within the calling String object of the first occurrence of the specified value, or -1 if not found.
5lastIndexOf()
Returns the index within the calling String object of the last occurrence of the specified value, or -1 if not found.
6localeCompare()
Returns a number indicating whether a reference string comes before or after or is the same as the given string in sort order.
7match()
Used to match a regular expression against a string.
8replace()
Used to find a match between a regular expression and a string, and to replace the matched substring with a new substring.
9search()
Executes the search for a match between a regular expression and a specified string.
10slice()
Extracts a section of a string and returns a new string.
11split()
Splits a String object into an array of strings by separating the string into substrings.
12substr()
Returns the characters in a string beginning at the specified location through the specified number of characters.
13substring()
Returns the characters in a string between two indexes into the string.
14toLocaleLowerCase()
The characters within a string are converted to lower case while respecting the current locale.
15toLocaleUpperCase()
The characters within a string are converted to upper case while respecting the current locale.
16toLowerCase()
Returns the calling string value converted to lower case.
17toString()
Returns a string representing the specified object.
18toUpperCase()
Returns the calling string value converted to uppercase.
19valueOf()
Returns the primitive value of the specified object.
You can also read our tutorial post on: Html Tables


String HTML Wrappers

Here is a list of the methods that return a copy of the string wrapped inside an appropriate HTML tag.

Sr.No.Method & Description
1anchor()
Creates an HTML anchor that is used as a hypertext target.
2big()
Creates a string to be displayed in a big font as if it were in a <big> tag.
3blink()
Creates a string to blink as if it were in a <blink> tag.
4bold()
Creates a string to be displayed as bold as if it were in a <b> tag.
5fixed()
Causes a string to be displayed in fixed-pitch font as if it were in a <tt> tag
6fontcolor()
Causes a string to be displayed in the specified color as if it were in a <font color="color"> tag.
7fontsize()
Causes a string to be displayed in the specified font size as if it were in a <font size="size"> tag.
8italics()
Causes a string to be italic, as if it were in an <i> tag.
9link()
Creates an HTML hypertext link that requests another URL.
10small()
Causes a string to be displayed in a small font, as if it were in a <small> tag.
11strike()
Causes a string to be displayed as struck-out text, as if it were in a <strike> tag.
12sub()
Causes a string to be displayed as a subscript, as if it were in a <sub> tag
13sup()
Causes a string to be displayed as a superscript, as if it were in a <sup> tag
In the following tutorials, we will have a few examples to demonstrate the usage of String methods. 

You can also read our tutorial post on: Html Attributes

Alright guys, we have come to the end of this wonderful tutorial post on JavaScript. Stay tuned because i will be dropping my next tutorial very soon. In my next tutorial i will make use of few examples to illustrate how JavaScript String properties can be used.

Drop your questions in the comment box below and they will be attended to as soon as possible. Don't forget to follow us on our various social media handles to stay updated with our latest tutorials, you can also subscribe to our email listing to get our tutorial posts delivered directly to your emails. Thanks for reading and bye for now.
Share:

0 comments:

Post a Comment