728x90
반응형
search()
search() 메서드는 문자열(정규식 포함)을 검색하고, 위치값을 숫자로 반환합니다.
search()
"문자열".search("검색값");
"문자열".search(정규식표현);
const str1 = "javascript reference";
const currentStr1 = str1.search("javascript"); //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("jquery"); //-1
const currentStr7 = str1.search("b"); //-1
const currentStr8 = str1.search(/[a-z]/g); //0
일치하는 문자열일 없을 경우 -1로 반환합니다.
'JavaScript' 카테고리의 다른 글
charAt( ) (2) | 2022.08.22 |
---|---|
match( ) (2) | 2022.08.22 |
toUpperCase( ) / toLowerCase( ) / trim( ) (1) | 2022.08.17 |
concat( ) / repeat( ) / includes( ) (2) | 2022.08.17 |
padStart( ) / padEnd( ) (2) | 2022.08.17 |
댓글