String.prototype.padEnd()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2017.
padEnd()
メソッドは、結果の文字列が指定した長さになるように、現在の文字列を他の文字列で(必要に応じて繰り返して)延長します。延長は、現在の文字列の末尾から適用されます。
試してみましょう
const str1 = "Breaded Mushrooms";
console.log(str1.padEnd(25, "."));
// Expected output: "Breaded Mushrooms........"
const str2 = "200";
console.log(str2.padEnd(5));
// Expected output: "200 "
構文
js
padEnd(targetLength)
padEnd(targetLength, padString)
引数
targetLength
-
現在の文字列の延長後に返される文字列の長さです。この値が現在の文字列の長さよりも短い場合、現在の文字列が返されます。
padString
省略可-
現在の文字列を延長するための文字列です。この文字列が
targetLength
に収まらないほど長い場合は、左書きの言語では最も左の部分が、右書きの言語では最も右の部分が使用され、残りは切り捨てられます。この引数の既定値は、 " " (U+0020
) です。
返値
String
で、 targetLength
で指定された長さにするために、 padString
を現在の str
の末尾に適用したものです。
例
padEnd の使用
js
"abc".padEnd(10); // "abc "
"abc".padEnd(10, "foo"); // "abcfoofoof"
"abc".padEnd(6, "123456"); // "abc123"
"abc".padEnd(1); // "abc"
仕様書
Specification |
---|
ECMAScript® 2025 Language Specification # sec-string.prototype.padend |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
padEnd |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
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.