Ordinal Suffix

Add an ordinal suffix to a number, returning formats like 1st, 2nd, 3rd, 4th.

Code

General
const s = ['th', 'st', 'nd', 'rd'];
const v = num % 100;
return num + (s[(v - 20) % 10] || s[v] || s[0]);

Parameters

The number to add suffix to

Browser·fetch() may be limited by CORS

More JavaScript Snippets