Languages
[Edit]
EN

JavaScript - String padStart() method example

0 points
Created by:
Inayah-Alexander
767

1. Documentation

Edit
Syntax

String padStart(maxLength)

String padStart(maxLength, fillString)

Parameters

maxLength- the length of the resulting string once the current string has been padded.

fillString - The string to pad the current string with.

ResultA String of the specified maxLength with fillString applied from the start.
Description

The method pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length. The padding is applied from the start (left) of the current string.

2. Practical example

Edit

In this example, we pad a number to keep only the last 3 digits.

Output:

See also

Edit
  1. JavaScript - pad left number in string with zeros or spaces to get determined length

References

Edit
  1. String.prototype.padStart() - JavaScript | MDN

Alternative titles

  1. JavaScript - String.prototype.padStart() documentation with examples
  2. js - String padStart() method documentation with examples
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

JavaScript - String (documentation)

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join