Answers for "find max index in array javascript"

3

how to find index of max number in js

var a = [0, 21, 22, 7];
var indexOfMaxValue = a.reduce((iMax, x, i, arr) => x > arr[iMax] ? i : iMax, 0);

document.write("indexOfMaxValue = " + indexOfMaxValue); // prints "indexOfMaxValue = 2"
Posted by: Guest on August-21-2020
3

how to find max in array

int[] a = new int[] { 20, 30, 50, 4, 71, 100};
		int max = a[0];
		for(int i = 1; i < a.length;i++)
		{
			if(a[i] > max)
			{
				max = a[i];
			}
		}
		
		System.out.println("The Given Array Element is:");
		for(int i = 0; i < a.length;i++)
		{
			System.out.println(a[i]);
		}
		
		System.out.println("From The Array Element Largest Number is:" + max);
Posted by: Guest on May-03-2020
1

how to return the max and min of an array in javascript

function minMax(arr) {
  return [Math.min(...arr), Math.max(...arr)];
}
Posted by: Guest on April-09-2020
0

javascript index of biggest number

arr.indexOf(Math.max(...arr))
Posted by: Guest on December-20-2019

Code answers related to "find max index in array javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language