charcodeat_JavaScript字符串charCodeAt()方法及示例

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值