includes()
이 메서드는 여태까지의 검색 메서드와는 다르게 반환을 불린값으로 해준다는 특징이 있습니다.
■ 문법
문자열 포함 여부를 검색해서 불린(true/false)로 반환합니다.
"문자열".includes(검색값)
"문자열".includes(검색값, 시작값)
■ 특징
▶ 검색값은 필수요소이며, 대소문자를 구분합니다.
▶ 시작값이 없으면 전체 문자열을 대상으로 합니다.
■ 예시
이해를 돕기 위해 예시를 들어봅시다. 주석으로 결과값을 작성하였습니다.
const str1 ="javascript reference";
const currentStr1 = str1.includes("javascript"); //true
const currentStr2 = str1.includes("j"); //true
const currentStr3 = str1.includes("b"); //false
const currentStr4 = str1.includes("reference"); //true
const currentStr5 = str1.includes("reference", 1); //true
const currentStr6 = str1.includes("reference", 11); //true
const currentStr7 = str1.includes("reference", 12); //false
728x90
'JavaScript' 카테고리의 다른 글
search() 메서드 (5) | 2022.08.22 |
---|---|
함수의 유형 (3) | 2022.08.22 |
padStart() / padEnd() 메서드 (6) | 2022.08.17 |
repeat()메서드 (6) | 2022.08.17 |
concat() 메서드 (4) | 2022.08.17 |
댓글