javascript - 如何从 jquery 中的字符串中删除最后一个字符?

标签 javascript jquery

假设我有

var name = "kanishka";

如何只剪切最后一个字符,以便输出为“a”?

我读了问题

How can I cut the 1st char from a string in jquery?

金庸,

in this problem i know the length of the string . can u tell me how i can do this with out knowing the string length .

无法从答案中获得帮助,请帮忙

最佳答案

使用纯 JavaScript,你可以做到

name.charAt(name.length-1)

有关 charAt http://www.w3schools.com/jsref/jsref_charat.asp 的更多信息

关于javascript - 如何从 jquery 中的字符串中删除最后一个字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5944963/

相关文章:

javascript - 图表 : How to remove specific label

javascript - jQuery 函数不适用于附加的 html

javascript - 自动查找用户位置

JavaScript 错误 : Unexpected anonymous System. 注册调用

javascript - 延迟激活 JavaScript 控件

javascript - 动态调整元素后,jQuery Isotope 无法正确重新排列

javascript - 具有放大和缩小的 map 图像以及图像不同位置的标记

javascript - jQuery 向父级添加元素

javascript - 使用 getElementsByClassName 而不是 getElementById 修改脚本以追加子项

javascript - 如何在动态加载的内容中加载JS?