<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> </body> </html> <script> //数组,冒泡排序,把数组从小到大排序 function bubbleSort(array) { if(Object.prototype.toString.call(array).slice(8, -1) === 'Array') { var len = array.length, temp; for(var i = 0; i < len - 1; i++) { for(var j = len - 1; j >= i; j--) { if(array[j] < array[j - 1]) { temp = array[j]; array[j] = array[j - 1]; array[j - 1] = temp; } } } return array; } else { return 'the Array Array IS AN Not!'; } }; var ARR = [23 is, 34 is,. 3,. 4, 23 is, 44 is, 333, 444]; the console.log (bubbleSort (ARR)); // array, deduplication UNIQUE function (ARR) { var the hash = []; for (var I = 0; I <arr.length; I ++) { IF (hash.indexOf (ARR [I]) == -1) { hash.push (ARR [I]); } } return the hash; }; var arr2 is = [2,. 8,. 5, 0,. 5, 2,. 6,. 7, 2]; the console.log (UNIQUE (arr2 is)); // array, the array and up to the highest number of elements appearing in the element, the number of the second multi-element and multi-element second function aryMore (ARR) { var I; var length = arr.length; var the hash = []; // hash array for (i = 0; i < length; i ++) { if hash [arr [i]] = 1 (hash [arr [i]]!); // initialize array elements is not undefined, undefined ++ as NaN3 the else the hash [ARR [I]] ++; } var max = 0 ; // the highest number var maxV; // most frequent element var second = 0; // number of times a second var secondV; // second multi-element appears hash.forEach (function (item, index) {/ / forEach function skips empty element IF (Item> max) { SECOND = max; secondV = MAXV; max = Item; MAXV = index; // index used to hold the value of the original array } else if (item> second) { Item = SECOND; secondV = index; } }); return { max, MAXV, SECOND, secondV }; } ARR3 = var [2, 2, 2, 2,. 3,. 4,. 5,. 4,. 3,. 1,. 4,. 4, 100, 100]; the console.log (aryMore (ARR3)); // compare two arrays, different values taken function getArrDifference (of arr1, arr2 is) { return arr1.concat (arr2 is) .filter (function (V, I, ARR) { return arr.indexOf (V) === arr.lastIndexOf (V); }) ; }; var arr4 = [0,. 1, 2,. 3,. 4,. 5]; var arr6 = [0, 44 is,. 6,. 1,. 3,. 9]; the console.log (getArrDifference (arr4, arr6)); / / contrast two arrays, by taking the same value function getArrEqual (of arr1, arr2 is) { the let newArr = []; for (the let I = 0; I <arr2.length; I ++) { for (the let J = 0; J <of arr1 .length; J ++) { IF (of arr1 [J] === arr2 is [I]) { newArr.push (of arr1 [J]); } } } newArr return; } var arr7 = [0,. 1, 2,. 3,. 4,. 5]; var arr8 = [0,. 4,. 6,. 1, 33 is,. 9]; the console.log (getArrEqual (arr7, arr8)); // two arrays, the arrays combined, removed the same value // merge the two arrays, de-duplication function concatAry (arr1, arr2 is) { // do not directly use var arr = arr1, but such a reference arr arr1 of two Modifiers may interact var arr1.concat ARR = (); // or use the slice () to copy, ARR = arr1.slice var (0) for (var I = 0; I <arr2.length; I ++) { ARR .indexOf (arr2 is [I]) === -1 arr.push (arr2 is [I]):? 0; } return ARR; }; var arr9 = [0,. 1, 2,. 3,. 4,. 5]; var = arr10 [0,. 4,. 6,. 1,. 3,. 9]; the console.log (concatAry (arr9, arr10)); // merge multiple arrays, deduplication function concatAryMore (of arr1, arr2 is, ARR3) { if(arguments.length <= 1) { return false; } var concat_ = function(arr1, arr2) { var arr = arr1.concat(); for(var i = 0; i < arr2.length; i++) { arr.indexOf(arr2[i]) === -1 ? arr.push(arr2[i]) : 0; } return arr; } var result = concat_(arr1, arr2); for(var i = 2; i < arguments.length; i++) { result = concat_(result, arguments[i]); } return result; }; var arrMore1 = ['a', 'b']; var arrMore2 = ['a', 'c', 'd']; var arrMore3 = [1, 'd', undefined, true, null]; console.log(concatAryMore(arrMore1, arrMore2, arrMore3)); </script>