
대소문자를 구분하지 않고 문자열이 시작하는지 확인하려면 toLowerCase() 메서드를 사용하여 문자열을 소문자로 변환한 후 startsWith() 메서드를 사용하면 됩니다.
예를 들어, 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
javascript
let str = "Hello World";
let substring = "hello";
if (str.toLowerCase().startsWith(substring)) {
console.log("문자열이 시작합니다.");
} else {
console.log("문자열이 시작하지 않습니다.");
}
이 코드는 대소문자를 구분하지 않고 "Hello World" 문자열이 "hello"로 시작하는지 확인합니다.
2025-03-20 14:09