D3.js maxIndex() Method

With the help of d3.maxIndex() method, we can get the index of value which is found to be maximum in an array of numbers, strings or dates. We can use any kind of array we just got the index of maximum value by using this method.

Syntax:

d3.maxIndex( iterable )

Parameter: This function has the following parameter as mentioned above and described below:

  • iterable: Insert any kind of iterable object.

Return Value: It will return the index of maximum value.



Note: To execute the below examples, you have to install the d3 library by using this command prompt we have to execute the following command.

npm install d3

Example 1: In this example, we can see that by using d3.maxIndex() method, we are able to find the index of a maximum value in an array of numbers, strings and date formatted by this method.

Filename: index.js

filter_none

edit
close

play_arrow

link
brightness_4
code

// Defining d3 contrib variable  
var d3 = require('d3');
  
var arr = []
for(var i = 0; i < 5; i++) {
    arr.push(i);
}
  
var index = d3.maxIndex(arr)
  
console.log(index)

chevron_right


Output:

4

Example 2: Filename: index.js

filter_none

edit
close

play_arrow

link
brightness_4
code

// Defining d3 contrib variable  
var d3 = require('d3');
  
var index = d3.maxIndex([new Date(), 
new Date("2020-09-01"), new Date("2020")])
  
console.log(index)

chevron_right


Output:

0

Note: The above program will compile and run by using the following command:

node index.js

Reference: https://github.com/d3/d3-array/blob/master/README.md

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.