ES6-문자열
String 객체를 사용하면 일련의 문자로 작업 할 수 있습니다. JavaScript의 문자열 프리미티브 데이터 유형을 여러 도우미 메서드로 래핑합니다.
JavaScript는 문자열 프리미티브와 String 객체 사이를 자동으로 변환하므로 문자열 프리미티브에서 String 객체의 도우미 메서드를 호출 할 수 있습니다.
다음 구문을 사용하여 String 개체를 만듭니다.
var val = new String(string);
문자열 매개 변수는 올바르게 인코딩 된 일련의 문자입니다. 끈.
문자열 속성
다음은 String 개체의 속성 및 설명 목록입니다.
Sr. 아니요 | 속성 및 설명 |
---|---|
1 | constructor Returns a reference to the String function that created the object . |
2 | length Returns the length of the string. |
3 | Prototype The prototype property allows you to add properties and methods to an object . |
String Methods
Here is a list of the methods available in String object along with their description.
Sr.No | Method & Description |
---|---|
1 | charAt() Returns the character at the specified index. |
2 | charCodeAt() Returns a number indicating the Unicode value of the character at the given index. |
3 | concat() Combines the text of two strings and returns a new string. |
4 | indexOf() Returns the index within the calling String object of the first occurrence of the specified value, or -1 if not found. |
5 | lastIndexOf() Returns the index within the calling String object of the last occurrence of the specified value, or -1 if not found. |
6 | localeCompare() Returns a number indicating whether a reference string comes before or after or is the same as the given string in a sorted order. |
7 | match() Used to match a regular expression against a string. |
8 | replace() Used to find a match between a regular expression and a string, and to replace the matched substring with a new substring. |
9 | search() Executes the search for a match between a regular expression and a specified string. |
10 | slice() Extracts a section of a string and returns a new string. |
11 | split() Splits a String object into an array of strings by separating the string into substrings. |
12 | substr() Returns the characters in a string beginning at the specified location through the specified number of characters. |
13 | substring() Returns the characters in a string between two indexes into the string. |
14 | toLocaleLowerCase() The characters within a string are converted to lower case while respecting the current locale. |
15 | toLocaleupperCase() The characters within a string are converted to uppercase while respecting the current locale. |
16 | toLowerCase() Returns the calling string value converted to lowercase. |
17 | toString() Returns a string representing the specified object. |
18 | toUpperCase() Returns the calling string value converted to uppercase. |
19 | valueOf() Returns the primitive value of the specified object. |