如何获取字符串中的最后一个字符? [英] How can I get the last character in a string?
本文介绍了如何获取字符串中的最后一个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我在 javascript 中有以下变量
If I have the following variable in javascript
var myString = "Test3";
从这个字符串中解析出3"的最快方法是什么适用于所有浏览器(回到 IE6)
what is the fastest way to parse out the "3" from this string that works in all browsers (back to IE6)
推荐答案
由于在 Javascript 中字符串是一个字符数组,您可以通过字符串的长度访问最后一个字符.
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];
这篇关于如何获取字符串中的最后一个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文