当前位置:网站首页>Remove the quotation marks that are numbers in the array
Remove the quotation marks that are numbers in the array
2022-07-20 12:07:00 【new Promise】
I thought of the problem when typing the code today : When using
split()
When the function converts a string to an array , The number inside will also becomestring
type .let str = 'abc123abc123'; let str1= str1.split(''); console.log(str1); // prints ['a', 'b', 'c', '1', '2', '3', 'a', 'b', 'c', '1', '2', '3']
You can call map
Function to remove the quotation marks that are numbers in the array , Make it into a number
type .
let str = 'abc123abc123';
let str2 = str.split('');
let newStr = str2.map(item => {
// Judge After converting this item into an array, it is not equal to NaN, Just perform the conversion operation
if (!isNaN(item - 0)) {
// Use + - And other mathematical symbols can be converted into Number data type
return item - 0;
} else {
return item;
}
});
console.log(newStr); // Print (12) ['a', 'b', 'c', 1, 2, 3, 'a', 'b', 'c', 1, 2, 3]
边栏推荐
- 小白学习MySQL - Generated Columns功能
- 已解决(selenium报错)AttributeError: ‘WebDriver‘ object has no attribute ‘execute_cdp_cmd‘
- 多层感知机如何调超参数
- 将Float类型的数字保留2位小数
- Shell function array job
- 为什么要学习Istio
- 23、网络原理——TCP/IP四层模型之中的重点协议(2)
- opencv(12):cv::rectangle学习与代码演示,使用opencv画矩形/矩形框
- GameFi 行业下滑但未出局| June Report
- 数据分析童鞋不容错过|实操风控业务分析报告
猜你喜欢
随机推荐
(CVPR-2022)具有密集 3D 表示和基准的野外步态识别
PMP证书含金量如何?值得考吗?
云呐-动环监控巡检表,信息机房巡检表
Dap+esb data warehouse construction process description
Rotate array 189, 153, 154, 33, 81, 10.03
Méthode d'évaluation des erreurs de cylindricité basée sur MATLAB
MySql索引类型和高性能索引学习总结
SPEC2006详细参数和测试过程常见问题处理总结(附实例操作)
【golang学习笔记1.7】 golang中的函数得使用
Win7安装系统,无猫腻
22、网络原理——TCP/IP四层模型之中的重点协议(1)
虚拟展会结合AI数字人,帮助企业解决当下困局
Restore 360 favorites method after the computer is damaged and the system is reinstalled, put 360sefav_ new_ 2021_ 07_ 16. Favdb files are copied to other computers. Files containing the character new
23、网络原理——TCP/IP四层模型之中的重点协议(2)
HCIA-R&S自用笔记(11)VRP文件系统、系统管理
关系抽取—OneRel
JSON. Parse error when parse occurs \n
C#入门系列(二十四) -- 密封类和静态类
2022年最新云开发去水印小程序源码
GameFi 行业下滑但未出局| June Report