JavaScript String normalize() Method
Last Updated :
11 Jul, 2024
Improve
JavaScript String normalize() method returns a Unicode normalization form of a given input string. If the given input is not a string, then at first it will be converted into a string then this method will work.
Syntax
string.normalize([form])
Parameters
Here the parameter is formed which is of many types-
- NFC: Normalization Form Canonical Composition.
- NFD: Normalization Form Canonical Decomposition.
- NFKC: Normalization Form Compatibility Composition.
- NFKD: Normalization Form Compatibility Decomposition.
These all say the Unicode Normalization Form.
Return value
It returns a new string containing the Unicode Normalization Form of the given input string.
Example 1: This example shows the basic use of the string.normalize() method in Javascript.
let a = "Geeks For Geeks";
b = a.normalize('NFC')
c = a.normalize('NFD')
d = a.normalize('NFKC')
e = a.normalize('NFKD')
console.log(b, c, d, e);
8
1
let a = "Geeks For Geeks";
2
3
b = a.normalize('NFC')
4
c = a.normalize('NFD')
5
d = a.normalize('NFKC')
6
e = a.normalize('NFKD')
7
8
console.log(b, c, d, e);
Output:
Geeks For GeeksGeeks For GeeksGeeks For GeeksGeeks For Geeks
Example 2: This example shows the basic use of the string.normalize() method in Javascript.
// Taking a string as input.
let a = "GeeksForGeeks";
// calling normalize method.
b = a.normalize('NFC')
c = a.normalize('NFD')
d = a.normalize('NFKC')
e = a.normalize('NFKD')
// Printing normalised form.
console.log(b);
console.log(c);
console.log(d);
console.log(e);
14
1
// Taking a string as input.
2
let a = "GeeksForGeeks";
3
4
// calling normalize method.
5
b = a.normalize('NFC')
6
c = a.normalize('NFD')
7
d = a.normalize('NFKC')
8
e = a.normalize('NFKD')
9
10
// Printing normalised form.
11
console.log(b);
12
console.log(c);
13
console.log(d);
14
console.log(e);
Output:
GeeksForGeeks
GeeksForGeeks
GeeksForGeeks
GeeksForGeeks
Supported Browsers
- Google Chrome 34
- Edge 12
- Firefox 31
- Opera 21
- Safari 10