Skip to content
Related Articles

Related Articles

Improve Article

D3.js greatestIndex() Method

  • Last Updated : 23 Sep, 2020

With the help of d3.greatestIndex() method, we can get the index of the largest value from the sequence of numbers in an array by using this method.

Syntax:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

d3.greatestIndex( iterable, accessor )

Return value: It returns the index of the largest 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.greatestIndex() method, we are able to get the index of the largest value from the sequence from an array by using this method.

Javascript




// Defining d3 contrib variable  
var d3 = require('d3');
  
var greatest_index =
  d3.greatestIndex([5, 4, 3, 2, 1]);
  
console.log(greatest_index);

Output:

0

Example 2:

Javascript




// Defining d3 contrib variable  
var d3 = require('d3');
  
var greatest_index =
  d3.greatestIndex([1.5, .44, 3.1, 2.12, 1.01]);
  
console.log(greatest_index);

Output:

2
My Personal Notes arrow_drop_up
Recommended Articles
Page :