charcodeat
字符串charCodeAt()方法 (String charCodeAt() Method)
charCodeAt() Method is a string method in JavaScript, it is used to get the Unicode of character at the specified index in the string.
charCodeAt()方法是JavaScript中的字符串方法,用于获取字符串中指定索引处的字符Unicode。
It accepts an index of the character and returns it's Unicode.
它接受字符的索引并返回其Unicode。
Note: If the index is not valid, it returns NaN. Read more: NaN in JavaScript.
注意:如果索引无效,则返回NaN 。 阅读更多: JavaScript中的NaN 。
Syntax:
句法:
String.charCodeAt(index);
Here,
这里,
String is the main string.
字符串是主要字符串。
index is the position of the character in the string.
index是字符在字符串中的位置。
Examples:
例子:
Input:
str = "IncludeHelp"
index = 0
Output:
73
Input:
str = "IncludeHelp"
index = 5
Output:
100
Code:
码:
<html>
<head>
<title>JavaScipt Example</title>
</head>
<body>
<script>
var str = "IncludeHelp";
var unicode = str.charCodeAt(0);
document.write(unicode + "<br>");
unicode = str.charCodeAt(5);
document.write(unicode + "<br>");
unicode = str.charCodeAt(-1);
document.write(unicode + "<br>");
unicode = str.charCodeAt(100);
document.write(unicode + "<br>");
</script>
</body>
</html>
Output
输出量
73
100
NaN
NaN
翻译自: https://www.includehelp.com/code-snippets/string-charCodeAt-method-with-example-in-javascript.aspx
charcodeat