1<! DOCTYPE html>234<meta charset= "UTF-8" >5<title></title>67<body>8<script>9 //defining the IndexOf functionTen //you can start at the specified location to find the next specified location that is worth the subscript One //if not found, return-1; A vararr=[1,2,3,2,1]; - functionindexOf (Arr,val,fromi) { - //if Fromi is undefined, the assignment is 0; thefromi===undefined&& (fromi=0); - //iterate through the remaining elements in Arr, starting with Fromi - for(vari=fromi;i<arr.length;i++){ - //if the current element equals Val + if(arr[i]==val) { - returnI//return I + } A } at return-1;//returns-1 - } - //Locate the next element with a value of 2 in Arr, starting at 0 position; -Console.log (IndexOf (arr,2,0));//1 - //find the next element with a value of 2 in arr, starting with a 2-bit position -Console.log (IndexOf (arr,2,2));//3 in //find the next element with a value of 2 in arr, starting with a 4-bit position -Console.log (IndexOf (arr,2,4));//-1 to //find the next element with a value of 4 in arr starting at 0 position +Console.log (IndexOf (arr,4,0));//-1 -</script> the</body> *Javascript-indexof function