Home > Web Front-end > JS Tutorial > js method to remove the first comma in a string_javascript skills

js method to remove the first comma in a string_javascript skills

WBOY
Release: 2016-05-16 16:45:24
Original
1707 people have browsed it
Copy code The code is as follows:




Here’s some better code:

Copy code The code is as follows:




The following mainly adds a method to remove multiple commas into one comma

Copy code The code is as follows:

function dostr(str){
str=trim(str);
var strarry=unique(str.split(","));
str=strarry.join(",");
str=str.replace(/,/ig,",");
str=str.replace(/[^0-9,]*/ig,"");
str=str.replace(new RegExp(', ',"gm"),',');
if (str.substr(0,1)==',') str=str.substr(1);
var reg=/,$/gi;
str=str.replace(reg ,"");
return str;
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template