Related Articles

Related Articles

JavaScript string.codePointAt() Method
  • Last Updated : 03 Sep, 2020

Below is the example of the string.codePointAt() Method.

  • Example:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <script> 
        a = "gfg"
      
        b = a.codePointAt(1); 
      
        document.write(b + "<br>"
    </script> 

    chevron_right

    
    

  • Output:
    102

The string.codePointAt() is an inbuilt method in JavaScript which is used to return a non-negative integer value i.e, code point value of the specified element of the given string.
List of code point values of different elements:

Syntax:

string.codePointAt(A)

Parameters: It accepts a parameter which shows the index of an element in the string. Index starts form zero (0).

Return Values: It returns the code point value of the element which is denoted by a parameter in the string. It returns undefined if there is no element present at the specified location i.e, at “A”th index.



JavaScript code to show the working of string.codePointAt() method:
Code #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
  
    // Taking a string "gfg"
    a = "gfg"
  
    // Pointing each elements of the string
    b = a.codePointAt(0);
    c = a.codePointAt(1);
    d = a.codePointAt(2);
  
    // Printing the code point value of each element
    document.write(b + "<br>")
    document.write(c + "<br>")
    document.write(d)
  
</script>

chevron_right


Output:

103
102
103

Code #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
  
    // Taking a string "gfg"
    a = "gfg"
  
    // Pointing 4th index of the string
    // index starts from 0
    b = a.codePointAt(3);
  
    // Printing the code point value
    document.write(b + "<br>")
  
</script>

chevron_right


Output:

undefined

Note: Output is undefined because in “gfg” there is no element at 4th index.

Supported Browsers:

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

full-stack-img




My Personal Notes arrow_drop_up
Recommended Articles
Page :