<String>.right()

Returns the n rightmost characters in a string

Usage
String = String.right(n, pad = null)
Member of:
String
Parameters:
  1. n – the Number of characters that the target stringshould take.
  2. pad – A single-character String that should be used to fill up the target string, if the source string was shorter than n (optional).
Returns:
String

Notes:

Examples

Simple examples:

"Lorem ipsum".right(0); // result: ""
"Lorem ipsum".right(1); // result: "m"
"Lorem ipsum".right(5); // result: "ipsum"
"Lorem ipsum".right(15); // result: "Lorem ipsum"

The last example shows that if the source string is shorter than the number given, this will just return the entire source string, but no more.

That is, unless you also specify a padding character:

"Lorem ipsum".right(15, "-"); // result: "----Lorem ipsum"

A good use-case for the padding option is the formatting of hexadecimal numbers:

(12).toString(16).right(4, "0"); // result: "000c" (= decimal 12)

Relevant JavaScript methods