- Javascript - Page Printing
- Javascript - Void Keyword
- Javascript - Dialog Boxes
- Javascript - Page Redirect
- Javascript - Cookies
- Javascript - Events
- Javascript - Functions
- Javascript - Loop Control
- Javascript - For...in
- Javascript - For Loop
- Javascript - While Loop
- Javascript - Switch Case
- Javascript - If...Else
- Javascript - Operators
- Javascript - Variables
- Javascript - Placement
- Javascript - Enabling
- Javascript - Syntax
- Javascript - Overview
- Javascript - Home
JavaScript Objects
- Javascript - HTML DOM
- Javascript - RegExp
- Javascript - Math
- Javascript - Date
- Javascript - Arrays
- Javascript - Strings
- Javascript - Boolean
- Javascript - Number
- Javascript - Objects
JavaScript Advanced
- Javascript - Browsers
- Javascript - Image Map
- Javascript - Debugging
- Javascript - Multimedia
- Javascript - Animation
- Javascript - Validations
- Javascript - Error Handling
JavaScript Useful Resources
- Javascript - Resources
- Javascript - Functions
- Javascript - Quick Guide
- Javascript - Questions And Answers
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
JavaScript - The Strings Object
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
Use the following syntax to create a String object −
var val = new String(string);
The String parameter is a series of characters that has been properly encoded.
String Properties
Here is a pst of the properties of String object and their description.
Sr.No. | Property & Description |
---|---|
1 | Returns a reference to the String function that created the object. |
2 | Returns the length of the string. |
3 | The prototype property allows you to add properties and methods to an object. |
In the following sections, we will have a few examples to demonstrate the usage of String properties.
String Methods
Here is a pst of the methods available in String object along with their description.
Sr.No. | Method & Description |
---|---|
1 | Returns the character at the specified index. |
2 | Returns a number indicating the Unicode value of the character at the given index. |
3 | Combines the text of two strings and returns a new string. |
4 | Returns the index within the calpng String object of the first occurrence of the specified value, or -1 if not found. |
5 | Returns the index within the calpng String object of the last occurrence of the specified value, or -1 if not found. |
6 | Returns a number indicating whether a reference string comes before or after or is the same as the given string in sort order. |
7 | Used to match a regular expression against a string. |
8 | Used to find a match between a regular expression and a string, and to replace the matched substring with a new substring. |
9 | Executes the search for a match between a regular expression and a specified string. |
10 | Extracts a section of a string and returns a new string. |
11 | Sppts a String object into an array of strings by separating the string into substrings. |
12 | Returns the characters in a string beginning at the specified location through the specified number of characters. |
13 | Returns the characters in a string between two indexes into the string. |
14 | The characters within a string are converted to lower case while respecting the current locale. |
15 | The characters within a string are converted to upper case while respecting the current locale. |
16 | Returns the calpng string value converted to lower case. |
17 | Returns a string representing the specified object. |
18 | Returns the calpng string value converted to uppercase. |
19 | Returns the primitive value of the specified object. |
String HTML Wrappers
Here is a pst of the methods that return a copy of the string wrapped inside an appropriate HTML tag.
Sr.No. | Method & Description |
---|---|
1 | Creates an HTML anchor that is used as a hypertext target. |
2 | Creates a string to be displayed in a big font as if it were in a <big> tag. |
3 | Creates a string to bpnk as if it were in a <bpnk> tag. |
4 | Creates a string to be displayed as bold as if it were in a <b> tag. |
5 | Causes a string to be displayed in fixed-pitch font as if it were in a <tt> tag |
6 | Causes a string to be displayed in the specified color as if it were in a <font color="color"> tag. |
7 | Causes a string to be displayed in the specified font size as if it were in a <font size="size"> tag. |
8 | Causes a string to be itapc, as if it were in an <i> tag. |
9 | Creates an HTML hypertext pnk that requests another URL. |
10 | Causes a string to be displayed in a small font, as if it were in a <small> tag. |
11 | Causes a string to be displayed as struck-out text, as if it were in a <strike> tag. |
12 | Causes a string to be displayed as a subscript, as if it were in a <sub> tag |
13 | Causes a string to be displayed as a superscript, as if it were in a <sup> tag |
In the following sections, we will have a few examples to demonstrate the usage of String methods.
Advertisements