String.prototype.trimEnd()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
String
값의 trimEnd()
메서드는 해당 문자열 마지막의 공백을 제거하고 원본 문자열의 수정 없이 새로운 문자열을 반환합니다. trimRight()
은 이 메서드의 별칭입니다.
시도해보기
const greeting = " Hello world! ";
console.log(greeting);
// Expected output: " Hello world! ";
console.log(greeting.trimEnd());
// Expected output: " Hello world!";
구문
js
trimEnd()
trimRight()
매개변수
없음.
반환 값
별칭
예제
trimEnd() 사용하기
다음 예제는 str
의 끝 부분에 있는 공백을 제거하지만, 시작 부분의 공백은 제거하지 않습니다.
js
let str = " foo ";
console.log(str.length); // 8
str = str.trimEnd();
console.log(str.length); // 6
console.log(str); // ' foo'
명세
Specification |
---|
ECMAScript® 2025 Language Specification # sec-string.prototype.trimend |
브라우저 호환성
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
trimEnd |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Uses a non-standard name.
- Has more compatibility info.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.