String.prototype.startsWith()
startsWith()
메서드는 어떤 문자열이 특정 문자로 시작하는지 확인하여 결과를 true
혹은 false
로 반환합니다.
시도해보기
구문
startsWith(searchString)
startsWith(searchString, position)
매개변수
searchString
-
문자열의 시작 지점에서 탐색할 문자열. 정규표현식이 올 수 없습니다.
position
Optional-
searchString
을 탐색할 위치. 기본값은0
.
반환 값
대상 문자열이 주어진 문자로 시작하면 true
, 아니면 false
.
예외
설명
startsWith
메소드로 어떤 문자열이 다른 문자열로 시작하는지 확인 할 수 있습니다. 대소문자를 구분합니다.
예제
startsWith()
사용하기
const str = "To be, or not to be, that is the question.";
console.log(str.startsWith("To be")); // true
console.log(str.startsWith("not to be")); // false
console.log(str.startsWith("not to be", 10)); // true
명세
Specification |
---|
ECMAScript Language Specification # sec-string.prototype.startswith |
브라우저 호환성
BCD tables only load in the browser