JavaScript 문자열은()를 포함합니다
예
문자열에 "world"가 포함되어 있는지 확인합니다.
let text = "Hello world, welcome to the universe.";
let result = text.includes("world");
let text = "Hello World, welcome to the universe.";
let result = text.includes("world", 12);
아래에 더 많은 예가 있습니다.
정의 및 사용
문자열에 지정된 문자열이 포함되어 있으면 메서드 includes()
가 반환 됩니다.true
그렇지 않으면 반환합니다 false
.
메서드 는 includes()
대소문자를 구분합니다.
통사론
string.includes(searchvalue, start)
매개변수
Parameter | Description |
searchvalue | Required. The string to search for. |
start | Optional. The position to start from. Default value is 0. |
반환 값
유형 | 설명 |
참이나 거짓. | true 문자열에 값이 포함되어 있으면 그렇지 않으면 false . |
더 많은 예
위치 12에서 시작:
let text = "Hello world, welcome to the universe.";
let result = text.includes("world", 12);
브라우저 지원
includes()
ECMAScript6(ES6) 기능입니다.
ES6(JavaScript 2015)은 모든 최신 브라우저에서 지원됩니다.
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
includes()
Internet Explorer 11(또는 이전)에서는 지원되지 않습니다.