Skip to content

Commit d6a1870

Browse files
Added padStart() and padEnd()
Added a code snippet that helps to add padding at the start or end of the string.
1 parent b017592 commit d6a1870

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

ECMASCript 2021/padding.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
// What's the use of `padStart()` and `padEnd()` in JavaScript?
2-
//
2+
33
// String padding is often needed to ensure consistent formatting.
44
// Common examples in ServiceNow:
55
// - Padding numeric IDs with leading zeros (e.g., "INC000045")
66
// - Making export data columns align neatly
77
// - Adding placeholders to strings for integration formatting
8-
//
8+
99
// padStart(targetLength, padString)
1010
// → Pads a string from the start until it reaches the target length
11-
//
11+
1212
// padEnd(targetLength, padString)
1313
// → Pads a string from the end until it reaches the target length
14-
//
14+
1515
// Example:
1616
// "1234".padStart(10, "x"); // → "xxxxxx1234"
1717
// "1234".padEnd(10, "y"); // → "1234yyyyyy"

0 commit comments

Comments
 (0)