JavaScript/기초
[JavaScript] startsWith, endsWith, includes
Lpla
2020. 11. 23. 22:19
반응형
string.startsWith(matchString) | matchString이 string의 문자로 시작하는지 여부 확인 |
string.endsWith(matchString) | matchString이 string의 문자로 끝나는지 여부 확인 |
string.includes(matchString) | matchString이 string의 문자를 포함하고 있는지 여부 확인 |
1. startsWith()
matchString이 string의 문자로 시작하는지 여부 확인 (true/false)
let str = "hello world!"
let matchstr1 = "hel"
console.log(str.startsWith(matchstr1)); //true
2. endsWith()
matchString이 string의 문자로 끝나는지 여부 확인 (true/false)
let str = "hello world!"
let matchstr2 = "rld!"
console.log(str.endsWith(matchstr2)); //true
3. includes
matchString이 string의 문자를 포함하고 있는지 여부 확인 (true/false)
let str = "hello world!"
let matchstr3 = "lo wo"
console.log(str.includes(matchstr3)); //true
반응형