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.
Code #1:
<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> |
Output:
103 102 103
Code #2:
<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> |
Output:
undefined
Note: Output is undefined because in “gfg” there is no element at 4th index.
Recommended Posts:
- Introduction to JavaScript Course | Learn how to Build a task tracker using JavaScript
- How to compare two JavaScript array objects using jQuery/JavaScript ?
- JavaScript Course | Understanding Code Structure in JavaScript
- JavaScript Course | Conditional Operator in JavaScript
- JavaScript Course | Data Types in JavaScript
- JavaScript Course | Printing Hello World in JavaScript
- JavaScript Course | Logical Operators in JavaScript
- JavaScript Course | Operators in JavaScript
- JavaScript Course | Functions in JavaScript
- JavaScript Course | Objects in JavaScript
- JavaScript Course | Loops in JavaScript
- JavaScript Course | Variables in JavaScript
- JavaScript Course | JavaScript Prompt Example
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
- How to include a JavaScript file in another JavaScript file ?
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.