JavaScript string.normalize() Method

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

  • Example:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <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> 

    chevron_right

    
    

  • 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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<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>

chevron_right


Output:

GeeksForGeeks
GeeksForGeeks
GeeksForGeeks
GeeksForGeeks

Reference:
http://devdocs.io/javascript/global_objects/string/normalize

Supported Browsers:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Apple Safari
  • Opera

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.