String.prototype.normalize()
Returns the Unicode Normalization Form of the string.
Syntax
str.normalize(form) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
form | string | No | One of 'NFC', 'NFD', 'NFKC', or 'NFKD'. Defaults to 'NFC'. |
Returns
string — A new string in the requested normalization form.
Throws
RangeError— form is not one of the valid values.
Examples
const a = 'ñ'; // ñ precomposed
const b = 'ñ'; // n + combining tilde
console.log(a === b, a.normalize() === b.normalize());
Output
false true
console.log('ẛ̣'.normalize('NFC').length);
Output
2
Notes
Essential for reliable string comparison of accented or composed characters.
NFC is the most common (canonical composition). Does not mutate the original.
Browser & runtime support
| Environment | Since version |
|---|---|
| chrome | 34 |
| firefox | 31 |
| safari | 10 |
| edge | 12 |
| node | 0.12 |