最近有个需求原数组[1@2,3#4,5^6]。
通过特殊字符限制数组[@,#,^]
得到过滤后的[1,2,3,4,5,6]
因为没有找到合适的函数所以用了while循环来完成
var chars = ['@','#','^']; for (var m = 0; m < chars.length; m++) { for (var l = 0; l < rule.length; l++) { var index = rule[l].indexOf(chars[m]) while (index > -1) { var cache = rule[l] rule.splice(l, 1) var cacheChars = cache.split(chars[m]) for (var n = 0; n < cacheChars.length; n++) { rule.splice(0, 0, cacheChars[n]) } index = rule[l].indexOf(chars[m]) } } }