The Wayback Machine - https://web.archive.org/web/20220708074837/https://www.geeksforgeeks.org/javascript-string-normalize/
Skip to content
Related Articles

Related Articles

JavaScript string.normalize() Method

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 06 Oct, 2021

Below is the example of the string.normalize() method. 
 

  • Example: 
     

javascript




<script>
var a = "Geeks For Geeks";
 
b = a.normalize('NFC')
c = a.normalize('NFD')
d = a.normalize('NFKC')
e = a.normalize('NFKD')
     
document.write(b,c,d,e);
</script>

  • Output: 
     
Geeks For GeeksGeeks For GeeksGeeks For GeeksGeeks For Geeks

The string.normalize() is an inbuilt method in javascript which is used to return a Unicode normalisation 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 form 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.
JavaScript code to show the working of string.normalize() method: 
 

javascript




<script>
 
  // Taking a string as input.
  var a = "GeeksForGeeks";
   
  // calling normalize method.
  b = a.normalize('NFC')
  c = a.normalize('NFD')
  d = a.normalize('NFKC')
  e = a.normalize('NFKD')
   
  // Printing normalised form.
  document.write(b +"<br>");
  document.write(c +"<br>");
  document.write(d +"<br>");
  document.write(e);
   
</script>

Output: 
 

GeeksForGeeks
GeeksForGeeks
GeeksForGeeks
GeeksForGeeks

Supported Browsers:  

  • Google Chrome 34 and above
  • Edge 12 and above
  • Firefox 31 and above
  • Opera 21 and above
  • Safari 10 and above

 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!