var arr = [4, 2, 5, 1, 3]; function fun1() { var len = arr.length; console.time('Tstart'); console.timeEnd('Tend'); } function diff(arr1, arr2) { //储存新数组 var newArr = []; //遍历这两个数组 for (var i = 0; i < arr1.length; i++) { if (arr2.indexOf(arr1[i]) === -1) { newArr.push(arr1[i]); } } for (var j = 0; j < arr2.length; j++) { if (arr1.indexOf(arr2[j]) === -1) { newArr.push(arr2[j]); } } return newArr; } diff([1, 2, 3, 5], [1, 2, 3, 4, 5])