博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何在JavaScript中删除字符串的最后一个字符
阅读量:2509 次
发布时间:2019-05-11

本文共 688 字,大约阅读时间需要 2 分钟。

How can you remove the last character from a string?

如何从字符串中删除最后一个字符?

The simplest solution is to use the slice() method of the string, passing 2 parameters. THe first is 0, the starting point. The second is the number of items to remove. Passing a negative number will remove starting from the end. This is the solution:

最简单的解决方案是使用字符串的slice()方法,并传递2个参数。 首先是0,即起点。 第二个是要删除的项目数。 传递负数将从末尾删除。 这是解决方案:

const text = 'abcdef'const editedText = text.slice(0, -1) //'abcde'

Note that the slice() method does not modify the original string.

请注意, slice()方法不会修改原始字符串。

It creates a new string, this is why I assign it to a new variable in the above example.

它创建了一个新字符串,这就是为什么在上面的示例中将其分配给新变量的原因。

翻译自:

转载地址:http://fmmgb.baihongyu.com/

你可能感兴趣的文章
ASP.NET MVC中的统一化自定义异常处理
查看>>
基于.net的aop实现技术
查看>>
桦仔 笔记7-徐 SQLSERVER日志记录机制
查看>>
下滑线驼峰互转
查看>>
Xcode 快捷键
查看>>
table_open_cache
查看>>
Java中super的几种用法并与this的区别
查看>>
C#利用NPOI操作Excel文件
查看>>
彻底了解指针数组,数组指针,以及函数指针 .
查看>>
浏览器兼容问题【转】
查看>>
python编程 之 PyMysql包接口,python中如何使用数据库
查看>>
WinForm 简单蒙版实现控件遮盖
查看>>
ASP.NET MVC ValueProvider小结
查看>>
ES6之路第二篇:变量的解构赋值
查看>>
iOS6新特征:UICollectionView介绍
查看>>
分享一个基于Bootstrap的 ACE框架 入门(MVC+EF)
查看>>
增量关联规则挖掘—FUP算法
查看>>
spring相关—AOP编程—切入点、连接点
查看>>
animation_Frame动画图片轮播
查看>>
BZOJ 4195 - 离散化 + 并查集
查看>>