Movatterモバイル変換


[0]ホーム

URL:


  1. 개발자를 위한 웹 기술
  2. JavaScript
  3. JavaScript 참고서
  4. 표준 내장 객체
  5. String
  6. String.prototype.endsWith()

This page was translated from English by the community.Learn more and join the MDN Web Docs community.

View in EnglishAlways switch to English

String.prototype.endsWith()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015년 9월⁩.

String 값의endsWith() 메서드는 문자열이 이 문자열의 문자로 끝나는지 여부를 결정하여 적절하게true 또는false를 반환합니다.

시도해 보기

const str1 = "Cats are the best!";console.log(str1.endsWith("best!"));// Expected output: trueconsole.log(str1.endsWith("best", 17));// Expected output: trueconst str2 = "Is this a question?";console.log(str2.endsWith("question"));// Expected output: false

구문

js
endsWith(searchString)endsWith(searchString, endPosition)

매개변수

searchString

str 끝에서 검색할 문자.정규 표현식이 될 수 없습니다. 정규식이 아닌 모든 값은 [문자열로 강제 변환]되므로 이를 생략하거나undefined를 전달하면endsWith()"undefined" 문자열을 검색하게 되는데, 이는 원하는 경우가 거의 없습니다.

endPositionOptional

searchString이 발견될 것으로 예상되는 끝 위치(searchString의 마지막 문자의 인덱스에 1을 더한 값)입니다. 기본값은str.length입니다.

반환 값

searchString이 빈 문자열인 경우를 포함하여 문자열 끝에 주어진 문자가 있으면 **true**를 반환하고, 그렇지 않으면 **false**를 반환합니다.

예외

TypeError

searchString정규 표현식이라면 발생합니다.

설명

이 메서드를 사용하면 문자열이 다른 문자열로 끝나는지 여부를 확인할 수 있습니다. 이 메서드는 대소문자를 구분합니다.

예제

endsWith() 사용하기

js
const str = "To be, or not to be, that is the question.";console.log(str.endsWith("question.")); // trueconsole.log(str.endsWith("to be")); // falseconsole.log(str.endsWith("to be", 19)); // true

명세서

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

브라우저 호환성

같이 보기

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp