1.模拟数组查找方法indexOf()
//arr代表数组,value代表查找的值
function findIndex(arr,value){
for(var i=0;i<arr.length;i++){
//arr[i]每个值
if(arr[i]==value){
return i;
}
}
return -1;
}
var arr = [1,3,5,6,8,4,2,1,5,6,8];
console.log(findIndex(arr,5)); //2
console.log(findIndex(arr,6)); //3
console.log(findIndex(arr,8)); //4
console.log(findIndex(arr,10)); //-1
2.模拟数组反转reverse()
//reverse()
//[1,2,3,4,5] [5,4,3,2,1]
//变量交换知识点,后面的值赋值给前面
// var x = 1;
// var y = 2;
// var z;
// z = x;
// x = y;
// y = z;
function reverseArr(arr) {
for (var i = 0; i < arr.length/2; i++) {
var x = ar