HTML: Markup language
CSS: Styling language
JavaScript: Scripting language
Web APIs: Programming interfaces
All web technology
Learn web development
Discover our tools
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
View in English Always switch to English
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015년 9월.
includes() 메서드는 하나의 문자열이 다른 문자열에 포함되어 있는지를 판별하고, 결과를 true 또는 false 로 반환합니다. 검색 시 대소문자를 구분합니다.
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"
includes(searchString) includes(searchString, position)
searchString
이 문자열에서 찾을 다른 문자열. 정규표현식이 올 수 없습니다.
position
searchString을 찾기 시작할 위치. (기본값 0).
0
문자열을 찾아내면 true . 실패하면 false .
TypeError
searchString이 정규식일 경우.
이 메서드를 사용해 문자열 내에 찾고자 하는 다른 문자열이 있는지 확인할 수 있습니다.
includes() 메서드는 대소문자를 구별합니다. 예를 들어 아래 코드는 false를 반환합니다.
"Blue Whale".includes("blue"); // returns false
아래와 같이 원본 문자열과 검색 문자열을 모두 소문자로 변환하여 이 제약 조건을 해결할 수 있습니다.
"Blue Whale".toLowerCase().includes("blue"); // returns true
const str = "To be, or not to be, that is the question."; console.log(str.includes("To be")); // true console.log(str.includes("question")); // true console.log(str.includes("nonexistent")); // false console.log(str.includes("To be", 1)); // false console.log(str.includes("TO BE")); // false console.log(str.includes("")); // true
Enable JavaScript to view this browser compatibility table.
core-js
String.prototype.includes
Array.prototype.includes()
TypedArray.prototype.includes()
String.prototype.indexOf()
String.prototype.lastIndexOf()
String.prototype.startsWith()
String.prototype.endsWith()