如何获取字符串的最后一个字符? [英] how to get the last character of a string?
本文介绍了如何获取字符串的最后一个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取字符串的最后一个字符:
How to get the last character of the string:
"linto.yahoo.com."
此字符串的最后一个字符是。
The last character of this string is "."
我怎样才能找到这个?
推荐答案
优雅是 String.prototype.slice
方法。
An elegant and short alternative, is the String.prototype.slice
method.
仅限:
str.slice(-1);
负起始索引从长度+索引$ c切割字符串$ c>,到
长度
,作为索引 -1
,提取最后一个字符:
A negative start index slices the string from length+index
, to length
, being index -1
, the last character is extracted:
"abc".slice(-1); // "c";
这篇关于如何获取字符串的最后一个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文