当前位置:网站首页>js去除字符串空格
js去除字符串空格
2022-06-24 12:59:00 【莉兹Liz】
js原生方法trim()
str = str.trim();
局限:只能去除字符串两边空格
let str = " 1 2 3 ";
str0 = str.trim();
// "1 2 3"
正则表达式
去除字符串所有空格
str = str.replace(/\s*/g,"");
去除字符串两边空格
str = str.replace(/^\s*|\s*$/g,"");
去除字符串左侧空格
str = str.replace(/^\s*/g,"");
去除字符串右侧空格
str = str.replace(/\s*$/g,"");
str1 = str.replace(/\s*/g,"");
// "123"
str2 = str.replace(/^\s*|\s*$/g,"");
// "1 2 3"
str3 = str.replace(/^\s*/g,"");
// "1 2 3 "
str4 = str.replace(/\s*$/g,"");
// " 1 2 3"
参考
边栏推荐
猜你喜欢

【R语言数据科学】(十四):随机变量和基本统计量

Seven challenges faced by data scientists and Solutions

谷歌WayMo提出R4D: 采用参考目标做远程距离估计

【5G NR】5G NR系统架构

Cloud native essay solicitation progress case practice

These default routes and static routes can not be configured and deployed. What kind of network workers are they!

Home office should be more efficient - automated office perfectly improves fishing time | community essay solicitation
![[R language data science] (XIV): random variables and basic statistics](/img/87/3606041a588ecc615eb8013cdf9fb1.png)
[R language data science] (XIV): random variables and basic statistics

npm包【详解】(内含npm包的开发、发布、安装、更新、搜索、卸载、查看、版本号更新规则、package.json详解等)

Harmony os. (2)
随机推荐
Prometheus pushgateway
Activity生命周期
Vulnerability management mistakes that CIOs still make
Promotion of Project Manager
项目经理搭建团队,需要看6个特征
kotlin 异步流
2022质量员-设备方向-通用基础(质量员)考试题及答案
kotlin 接口 泛型 协变 逆变
kotlin 初始化块
Dragon lizard developer said: first time you got an electric shock, so you are such a dragon lizard community| Issue 8
2022年质量员-设备方向-岗位技能(质量员)复训题库及在线模拟考试
这几个默认路由、静态路由的配置部署都不会,还算什么网工!
Google Earth Engine——1999-2019年墨累全球潮汐湿地变化 v1 数据集
Docker installation redis
首席信息安全官仍然会犯的漏洞管理错误
kotlin 协程上下文和调度器
Daily question 8-515 Find the maximum value in each tree row
90%的项目经理都跳过的坑,你现在还在坑里吗?
10 个 Reduce 常用“奇技淫巧”
HarmonyOS-3