Answers for "looping arrays: the for-of loop js"

13

array loop js

var arr = ["f", "o", "o", "b", "a", "r"]; 
for(var i in arr){
	console.log(arr[i]);
}
Posted by: Guest on November-12-2021
0

arrays with for loops

// Find-Max variant -- rather than finding the max value, find the
// *index* of the max value
public int findMaxIndex(int[] nums) {
  int maxIndex = 0;  // say the 0th element is the biggest
  int maxValue = nums[0];

  // Look at every element, starting at 1
  for (int i=1; i<nums.length; i++) {
    if (nums[i] > maxValue) {
      maxIndex = i;
      maxValue = nums[maxIndex];
    }
  }
  return maxIndex;
}
Posted by: Guest on May-15-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language