JavaScript Tutorial

String In JavaScript
Previous Home Next

A JavaScript string simply stores a series of characters like "prasun".

Creating a String object

Syntax :

var val = new String(string);

String Properties:

Property Description
constructor Returns a reference to the String function
length Returns the length of the string.
prototype The prototype property allows you to add properties and methods to an object.

 

String Methods :

Property Description
indexOf() Returns the index within the calling String object of the first occurrence of the specified value
concat() Combines the text of two strings and returns a new string.
charAt() Returns the character at the specified index.
charCodeAt() Returns a number indicating the Unicode value
match() match a regular expression against a string.
replace() Searches a string for a value and returns a new string with the value replaced
localeCompare() Compares two strings in the current locale
slice() Extracts a section of a string and returns a new string.
substring() Returns the characters in a string between two indexes into the string.
toString() Returns a string representing the specified object.
toLowerCase() Returns the calling string value converted to lower case.
toUpperCase() Returns the calling string value converted to uppercase.
valueOf() Returns the primitive value of a String object
split() Splits a string into an array of substrings

String HTML wrappers :

Method Description
blink() Creates a string to blink as if it were in a <blink> tag.
bold() Creates a string to be displayed as bold as if it were in a <b> tag.
anchor() Creates an HTML anchor that is used as a hypertext target.
fontcolor() Causes a string to be displayed in the specified color as if it were in a <font color="color"> tag.
fixed() Causes a string to be displayed in fixed-pitch font as if it were in a <tt> tag
link() Creates an HTML hypertext link that requests another URL.
sub() Causes a string to be displayed as a subscript, as if it were in a <sub> tag
sup() Causes a string to be displayed as a superscript, as if it were in a <sup> tag
Previous Home Next

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback: