The JavaScript string is a character sequence that is represented as an object. A string can be any combination of letters, integers, special characters, and arithmetic values.
Ways to create string
Double quotes are used to build the string literal. Lets take an example
var val="Example string literal";
console.log(val); // Example string literal
We use new keyword for creating string object
var val = new String("Example string object");
console.log(val); // Example string object
Method | Description | Example |
---|---|---|
charAt() | It returns the char value found at the given index. |
|
concat() | It returns the char value found at the given index. |
|
indexOf() | It returns the char value found at the given index. |
|
lastIndexOf() | It returns the char value found at the given index. |
|
toLowerCase() | It returns the char value found at the given index. |
|
toUpperCase() | It returns the char value found at the given index. |
|
slice(startIndex, endIndex) | It returns the char value found at the given index. |
|
trim() | It returns the char value found at the given index. |
|
split() | It returns the char value found at the given index. |
|
replace() | It returns the char value found at the given index. |
|
substr() | It returns the char value found at the given index. |
|
valueOf() | It returns the char value found at the given index. |
|