a = "01,02,03,04,05,06|a1,a2,a3"
b = "03,05,07,09,10|a2,b1,b2,b3,b5"
a = a.split(/[,\|]/g)
b = b.split(/[,\|]/g)
var kv = {},arrSame=[]
for (var i = 0; i < a.length; i++) kv[a[i]] = true;
for (var i = 0; i < b.length; b++) if (kv[b[i]]) arrSame.push(b[i])
a = "01,02,03,04,05,06|a1,a2,a3"
b = "03,05,07,09,10|a2,b1,b2,b3,b5"
a = a.split(/[,\|]/g)
b = b.split(/[,\|]/g)
var kv = {},arrSame=[]
for (var i = 0; i < a.length; i++) kv[a[i]] = true;
for (var i = 0; i < b.length; b++) if (kv[b[i]]) arrSame.push(b[i])
alert(arrSame.join()+'\n'+arrSame.length)
#2
a = "01,02,03,04,05,06|a1,a2,a3"
b = "03,05,07,09,10|a2,b1,b2,b3,b5"
a = a.split(/[,\|]/g)
b = b.split(/[,\|]/g)
var kv = {},arrSame=[]
for (var i = 0; i < a.length; i++) kv[a[i]] = true;
for (var i = 0; i < b.length; b++) if (kv[b[i]]) arrSame.push(b[i])
alert(arrSame.join()+'\n'+arrSame.length)
谢谢,代码有点小问题,没有正确显示
#3
a = "01,02,03,04,05,06|a1,a2,a3"
b = "03,05,07,09,10|a2,b1,b2,b3,b5"
a = a.split(/[,\|]/g)
b = b.split(/[,\|]/g)
var kv = {},arrSame=[]
for (var i = 0; i < a.length; i++) kv[a[i]] = true;
for (var i = 0; i < b.length; b++) if (kv[b[i]]) arrSame.push(b[i])