Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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"
Comment

js find all max number indexes in array

const arr = [0,1,4,3,4];
const max = Math.max(...arr);
let res = [];
arr.forEach((item, index) => item === max ? res.push(index): null);
console.log(res);
Comment

PREVIOUS NEXT
Code Example
Javascript :: conditionally add a property to an object 
Javascript :: jquery get all checked checkboxes 
Javascript :: javascript remove src from img 
Javascript :: javascript readfile 
Javascript :: bubble sort javascript 
Javascript :: set port nextjs 
Javascript :: three.js create sphere 
Javascript :: javascript .split().reverse.join 
Javascript :: how to clear nodemon cache 
Javascript :: confirm delete message in jquery 
Javascript :: toggle bootstrap modal with jquery 
Javascript :: js get home url 
Javascript :: open link in new window chrome mac shortcut 
Javascript :: get iso date javascript 
Javascript :: clearinterval in useeffect 
Javascript :: process.now() nodejs 
Javascript :: credit card regex javascript 
Javascript :: npm font awesome vue 
Javascript :: concurrently node react 
Javascript :: jquery on click get element 
Javascript :: jacksepticeye 
Javascript :: javascript select random element from array 
Javascript :: react hide source code 
Javascript :: jquery scroll to id 
Javascript :: nodejs put array in file 
Javascript :: if window undefined 
Javascript :: javascript middle of array 
Javascript :: converting bytes into kb js 
Javascript :: javascript string to integer 
Javascript :: Check if a JavaScript string is a URL 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =