Elementals.js

Latest Version: 3.7 Final 20 December 2018

Method String.pad

Summary:

Pads a string

Calling Convention:
String.pad(count[, character])
Parameters
count

The number of characters to pad the string by. If this value is positive the characters will be added to the end of the string. If negative they will be added to the beginning of the string. If the string is longer than this number, the returned string will be unchanged.

Note, if you pass a non-numeric value, this WILL throw an error.

character Optional
The character to be repeated. If omitted a space will be used. Should you pass a string longer than one character to this routine, only the first character of that string will be used!
Returns:
The new padded string result.

JavaScript

console.log(String('test').pad(8, 'x')); // 'testxxxx'
console.log(String('test').pad(-8, 'x')); // 'xxxxtest'

Elementals String Methods

Elementals Extensions

Polyfills

These link to the Mozilla Developer Network (MDN)

Property Key

  • Object
  • Method or Variable
  • "Constant" Variable

Downloads

Advertisement