
search()
문자열(정규식)을 검색하고, 위치 값(숫자)을 반환한다.
"문자열".search("검색값");
"문자열".search(정규식 표현);
const str1 ="javascript reference"
const currentStr1 = str1.search("javascipt"); // 0
const currentStr2 = str1.search("reference"); // 11
const currentStr3 = str1.search("j"); // 0
const currentStr4 = str1.search("a"); // 1
const currentStr5 = str1.search("v"); // 2
const currentStr6 = str1.search("jqeurey"); // -1
const currentStr7 = str1.search("b"); // -1
const currentStr8 = str1.search(/[a-z]/g); // 0
'JAVASCRIPT' 카테고리의 다른 글
메서드 (charAt) (3) | 2022.08.22 |
---|---|
메서드 (match) (3) | 2022.08.22 |
메서드 (trim / trimStart / trimEnd) (2) | 2022.08.18 |
메서드 (includes) (2) | 2022.08.18 |
메서드 (padStart / padEnd) (2) | 2022.08.17 |
댓글