String object for getting started with javascript [required for beginners] 1. String object
String object is used to process text (String ).
Ii. Constructor
New String (value) // Constructor
Function String (value) // Conversion function
Iii. Attributes
Length: the number of characters in the string.
Var str = new String ("abcdefg"); document. write (str. length); // output 7
Iv. Methods
1. chatAt () is used to retrieve characters at the specified position in a string.
Var str = new String ("abcdefg"); document. write (str. charAt (1); // output B
2. chatCodeAt () returns the encoding of characters at the specified position in a string.
Var str = new String ("abcdefg"); document. write (str. charCodeAt (1); // output 98
3. concat () concatenates one or more values into one string.
Var str = new String ("abcdefg"); var str1 = "hijk"; document. write (str. concat (str1); // output abcdefghijk
4. indexOf () searches for a character or string position in the specified string. If no result is found,-1 is returned.
Syntax: indexOf (str) str: substring or character
IndexOf (str, start) str: a substring or character. Start: Specifies the start position of the search.
Var str = new String ("abccba"); document. write (str. indexOf ('B'); // output 1document. write (str. lastIndexOf ("bc"); // output 1
Use this method to implement the Contains effect and determine whether a string Contains another string: