在javascript中,如何获取字符串中的最后一个字符 [英] in javascript, how can i get the last character in a string
本文介绍了在javascript中,如何获取字符串中的最后一个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我在javascript中有以下变量
If I have the following variable in javascript
var myString = "Test3";
从这个字符串解析出3的最快方法是什么?所有浏览器(返回IE6 )
推荐答案
因为在Javascript中字符串是char数组,所以你可以访问最后一个字符的字符串长度。
Since in Javascript a string is a char array, you can access the last character by the length of the string.
var lastChar = myString[myString.length -1];
这篇关于在javascript中,如何获取字符串中的最后一个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文