JavascriptcharCodeAt obtains the Unicode encoding of a specific character in a string.

Source: Internet
Author: User
In javascript, you can use the charAt () function to obtain characters at the specified position in a string. If you want to obtain the Unicode encoding of this character, what function should you use. The charCodeAt function in javascript can obtain the Unicode encoding of a specific character in a string. This article describes how to use charCodeAt. The charCodeAt () method returns the Unicode encoding of characters at the specified position. The returned value is an integer between 0 and 65535. This method is similar to the charAt () method, except that the former returns the encoding of the characters at the specified position, and the latter returns the character substrings.

Basic syntax

strObj.charCodeAt(index)

Parameter Introduction

Parameters Description
Index Required. Number that counts the characters to be processed from scratch. The valid value is a number ranging from 0 to 1 minus the string length.

Description

  1. The first character in a string is 0, the second character is 1, and so on.
  2. If the specified position does not contain any characters, NaN is returned.

Instance:

The following example illustrates the usage of the charCodeAt method.

Script function charCodeAtTest (n) {var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // initialize the variable. Var n; // declare the variable. N = str. charCodeAt (n-1); // obtain the Unicode value of the character at the position n. Return (n); // return this value .} Document. write (charCodeAtTest (3); // output the Unicode code of D, script

Online operation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.