正则表达式去重

var str = 'afjasoeigjs123sgdh1edhhe456osddhnofd789';
var reg = str.replace(/[^0-9]/ig, "");

var arr2 = [];
for (var i = 0; i < reg.length; i++) {
if (arr2.indexOf(reg[i]) < 0) {
arr2.push(reg[i])
}
}
console.log(arr2);

posted @ 2020-08-30 18:36  文采呱呱  阅读(564)  评论(0编辑  收藏  举报