//像一个数组添加数组。 copyArray = function(inSrcArray,inDestArray){ var i; for(i=0;i<inSrcArray.length;i++){ inDestArray.push(inSrcArray[i]); } return inDestArray; } var newArray =copyArray([1,5,5,11],[5,8]); console.log(newArray); //[5,8,1,5,5,11] //在一个数组中查找值。 findArray = function (inArray,inValue) { var i; for(i=0;i<inArray.length;i++){ if (inArray[i]==inValue){ return i; } } return -1; } var right = findArray([9,11,2,4],11); console.log(right);//1 //求数组内数字的平均值 arrayAverage = function (inArray) { var accumulator=0; var i; for(i=0;i<inArray.length;i++){ accumulator += inArray[i]; } return accumulator/inArray.length; } var num = arrayAverage([7,9,66,1]); console.log(num);