Javascript build-in String object reference.
Create strings:
To create an object: | new String([param]) |
You uses the new keyword to create an object that contains a primitive string. | |
To use as a function: | String([param]) |
When the String object is used as a function the return will be a primitive string. | |
param: | The param argument is optional. If it is present it can be one of the following:
|
An example of using the new String(date):
|
General information about the object member types:
- Prototype created methods, properties or constants can only be used on instances of an object or on a primitive datatype.
- Constructor created methods, properties or constants can NOT be used on instances of an object or on a primitive datatype.
Prototype Methods:
Syntax: | charAt(index) |
This method returns a one-character string from index position in a string.
All characters in a string has an index starting with 0 as the first character and length-1 as the last character. In some implementations you can use a different notation, string [index], to achieve the same. |
|
Return value: | A primitive string. |
index: | This is the index of the character that should be returned from a string. |
An example of using the charAt() :
|
Constructor (String) Methods:
Syntax: | String.fromCharCode(c1,c2, ...) |
Returns a string containing as many characters as the number of arguments.
Each argument specifies one character of the resulting string, with the first argument specifying the first character, and so on, from left to right. |
|
Return value: | A primitive string. |
c1,c2, ... : | One or more codes that will be converted to characters. |
An example of using the fromCharCode() :
|
Prototype Properties:
Syntax: | String.prototype.constructor |
This property of the String.prototype holds the reference back to the String object. | |
Important note: | This is the same as the constructor property of an instantiated object |
Constructor (String) Properties:
Syntax: | String.constructor |
The constructor property is a reference to the function that will be invoked to create a String object. |
© 2010 by Finnesand Data.
All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the
correctness in the pages or source codes.
The risk of using this web-site pages or any program
codes from this website is entirely at the individual user.