Open In App

D3.js greatestIndex() Method

Last Updated : 23 Sep, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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:

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

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads