发布网友 发布时间:2022-04-23 16:36
共1个回答
热心网友 时间:2022-04-22 20:03
如果数组中个元素是字符串,这么做方便,如果不是,那就用@lyw_2008_happy的方法就行<br><br>var arr1 = ['a','b','c','d']; <br>var arr2 = ['x','b','c','y'];<br>var long = arr1.length<arr2.length?arr2:arr1;<br>var short = arr1.length<arr2.length?arr1:arr2;<br>var str = ","+long.toString()+",";<br>var result=[];<br>for(var i in short){<br> if(str.indexOf(","+short[i]+",")>=0){<br> result.push(short[i]);<br> }<br>}<br>alert(result.toString());