--- title: String.prototype.padEnd() slug: Web/JavaScript/Reference/Global_Objects/String/padEnd tags: - JavaScript - Method - Reference - String translation_of: Web/JavaScript/Reference/Global_Objects/String/padEnd ---
padEnd() 메서드는 현재 문자열에 다른 문자열을 채워, 주어진 길이를 만족하는 새로운 문자열을 반환합니다. 채워넣기는 대상 문자열의 끝(우측)부터 적용됩니다.
str.padEnd(targetLength [, padString])
targetLengthpadString {{optional_inline}}끝부터 주어진 문자열로 채워 목표 길이를 만족하는 {{jsxref("String")}}
'abc'.padEnd(10); // "abc " 'abc'.padEnd(10, "foo"); // "abcfoofoof" 'abc'.padEnd(6, "123456"); // "abc123" 'abc'.padEnd(1); // "abc"
다른 모든 코드 이전에 아래 코드를 포함하면 지원하지 않는 플랫폼에서도 String.prototype.padStart() 메서드를 사용할 수 있습니다.
// https://github.com/uxitten/polyfill/blob/master/string.polyfill.js
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd
if (!String.prototype.padEnd) {
String.prototype.padEnd = function padEnd(targetLength,padString) {
targetLength = targetLength>>0; //floor if number or convert non-number to 0;
padString = String((typeof padString !== 'undefined' ? padString : ' '));
if (this.length > targetLength) {
return String(this);
}
else {
targetLength = targetLength-this.length;
if (targetLength > padString.length) {
padString += padString.repeat(targetLength/padString.length); //append to original to ensure we are longer than needed
}
return String(this) + padString.slice(0,targetLength);
}
};
}
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('ESDraft', '#sec-string.prototype.padend', 'String.prototype.padEnd')}} | {{Spec2('ESDraft')}} | Initial definition in ECMAScript 2017. |
| {{SpecName('ES8', '#sec-string.prototype.padend', 'String.prototype.padEnd')}} | {{Spec2('ES8')}} |
The compatibility table in 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.
{{Compat("javascript.builtins.String.padEnd")}}