Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use JavaScript’s Intl.PluralRules with { type: "ordinal" } to choose the correct English suffix, then append it to the number. This handles cases such as 11th and 21st without hand-written exception logic.

Use Intl.PluralRules for English ordinals

The Intl.PluralRules API can select ordinal categories for ranking numbers. For English, map those categories to the suffixes st, nd, rd, and th:

const ordinalRules = new Intl.PluralRules("en-US", { type: "ordinal" });
const suffixes = new Map([
  ["one", "st"],
  ["two", "nd"],
  ["few", "rd"],
  ["other", "th"],
]);

function toOrdinal(n) {
  return `${n}${suffixes.get(ordinalRules.select(n))}`;
}

console.log(toOrdinal(1));   // 1st
console.log(toOrdinal(2));   // 2nd
console.log(toOrdinal(3));   // 3rd
console.log(toOrdinal(11));  // 11th
console.log(toOrdinal(21));  // 21st

Construct the rules with new and set type: "ordinal". The constructor otherwise uses cardinal rules, which are for quantities rather than rankings. select(n) returns a category; the map supplies its English suffix. The MDN constructor reference documents outputs including 0th, 1st, 2nd, 3rd, 4th, 11th, 21st, 42nd, and 103rd.

Why 11th and 21st have different endings

The ending depends on the ordinal category, not just the final digit. In English, 11, 12, and 13 take th, while 21, 22, and 23 take st, nd, and rd. Using Intl.PluralRules avoids the common bug of assigning a suffix solely by checking the last digit.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose a locale and define your input rules

Specify the intended locale, such as en-US, when English output is required. Keep the numeric value separate from its displayed ordinal if your application may later localize the text or sort the underlying values.

The example is intended for ordinary numeric inputs. Define how your application should handle non-integers, NaN, infinities, numeric strings, and negative values; the cited MDN examples do not establish a product-specific validation policy.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When a manual helper may be enough

A small hand-written helper can suit an English-only script or an environment without Intl.PluralRules, but it must account for the 11–13 exception as well as the ordinary last-digit endings. For maintainable code that may need locale-aware behavior, the native API is the stronger default. MDN marks Intl.PluralRules widely available and says it has been available across browsers since September 2019.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.