Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

이 페이지는 영어로부터 커뮤니티에 의하여 번역되었습니다. MDN Web Docs에서 한국 커뮤니티에 가입하여 자세히 알아보세요.

String.prototype.includes()

BaselineWidely available

includes() 메서드는 하나의 문자열이 다른 문자열에 포함되어 있는지를 판별하고, 결과를true 또는false 로 반환합니다. 검색 시 대소문자를 구분합니다.

시도해 보기

const sentence = "The quick brown fox jumps over the lazy dog.";const word = "fox";console.log(  `The word "${word}" ${    sentence.includes(word) ? "is" : "is not"  } in the sentence`,);// Expected output: "The word "fox" is in the sentence"

구문

js
includes(searchString)includes(searchString, position)

매개변수

searchString

이 문자열에서 찾을 다른 문자열. 정규표현식이 올 수 없습니다.

positionOptional

searchString을 찾기 시작할 위치. (기본값0).

반환값

문자열을 찾아내면true . 실패하면false .

예외

설명

이 메서드를 사용해 문자열 내에 찾고자 하는 다른 문자열이 있는지 확인할 수 있습니다.

대소문자 구분

includes() 메서드는 대소문자를 구별합니다. 예를 들어 아래 코드는false를 반환합니다.

js
"Blue Whale".includes("blue"); // returns false

아래와 같이 원본 문자열과 검색 문자열을 모두 소문자로 변환하여 이 제약 조건을 해결할 수 있습니다.

js
"Blue Whale".toLowerCase().includes("blue"); // returns true

예제

includes() 사용하기

js
const str = "To be, or not to be, that is the question.";console.log(str.includes("To be")); // trueconsole.log(str.includes("question")); // trueconsole.log(str.includes("nonexistent")); // falseconsole.log(str.includes("To be", 1)); // falseconsole.log(str.includes("TO BE")); // falseconsole.log(str.includes("")); // true

명세

Specification
ECMAScript® 2026 Language Specification
# sec-string.prototype.includes

브라우저 호환성

같이 보기

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp