The normalize() method of the String class in JavaScript returns the Unicode Normalization Form of the calling string value.
There are 2 variations for the syntax of String.normalize() method. They are:
normalize()
This method returns the Unicode Normalization Form of the calling string value using the default normalization form (NFC).
Returns value of type String
.
normalize(form)
Parameters
Parameter | Optional/Required | Description |
---|---|---|
form | optional | A string representing the Unicode Normalization Form. Possible values are 'NFC', 'NFD', 'NFKC', and 'NFKD'. |
This method returns the Unicode Normalization Form of the calling string value using the specified normalization form.
Returns value of type String
.
In JavaScript, we can use the normalize()
method to normalize a string to the default Unicode Normalization Form (NFC).
For example,
str
with a value that contains a character in a composed form and its decomposed equivalent.normalize()
method with no arguments to normalize the string to the default form.normalizedStr
.normalizedStr
to the console using the console.log()
method.const str = '\u1E9B\u0323';
const normalizedStr = str.normalize();
console.log(normalizedStr);
ṩ
In JavaScript, we can use the normalize()
method to normalize a string to the NFD (Normalization Form D) form.
For example,
str
with a value that contains a character in composed form.normalize()
method with the argument 'NFD'
to normalize the string to the NFD form.normalizedStr
.normalizedStr
to the console using the console.log()
method.const str = '\u1E9B\u0323';
const normalizedStr = str.normalize('NFD');
console.log(normalizedStr);
ṩ
In JavaScript, we can use the normalize()
method to normalize a string to the NFKC (Normalization Form KC) form.
For example,
str
with a value that contains a character in composed form.normalize()
method with the argument 'NFKC'
to normalize the string to the NFKC form.normalizedStr
.normalizedStr
to the console using the console.log()
method.const str = '\uFB01';
const normalizedStr = str.normalize('NFKC');
console.log(normalizedStr);
fi
In this JavaScript tutorial, we learned about normalize() method of String: the syntax and few working examples with output and detailed explanation for each example.