JavaScript | string.codePointAt()

The string.codePointAt() is an inbuilt function 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 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() function:

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.



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.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.