已知 arr1 = ['a','b','c','d','a','c'],arr2=['x','b','c','y','c','a'],用js取两个数组相同的元素,返回一个新数组,数组要求没有重复元素

//js代码如下:
1
function fnTogether(arr1,arr2){ 2 var newArr = []; 3 for (var i = 0; i < arr1.length; i++) { 4 for(var j = 0; j < arr2.length; j++){ 5 if(arr1[i] == arr2[j]){ 6 if(newArr.indexOf(arr1[i]) == -1){ 7 newArr.push(arr1[i]); 8 } 9 } 10 } 11 } 12 return newArr; 13 } 14 alert(fnTogether(arr1,arr2));

 

posted on 2018-10-26 17:44  bitkuang  阅读(837)  评论(0编辑  收藏  举报

导航