D3.js greatestIndex() Method
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
var d3 = require( 'd3' );
var greatest_index =
d3.greatestIndex([5, 4, 3, 2, 1]);
console.log(greatest_index);
|
Output:
0
Example 2:
Javascript
var d3 = require( 'd3' );
var greatest_index =
d3.greatestIndex([1.5, .44, 3.1, 2.12, 1.01]);
console.log(greatest_index);
|
Output:
2
Last Updated :
23 Sep, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...