Wednesday, July 3, 2024
HomeLanguagesJavascriptD3.js minIndex() Method

D3.js minIndex() Method

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

Syntax:

d3.minIndex( 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 minimum 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.minIndex() method, we are able to find the index of a minimum value in an array of numbers, strings and date formatted by this method.

Filename: index.js




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


Output:

0

Example 2: Filename: index.js




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


Output:

2

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Dominic Rubhabha Wardslaus
Dominic Rubhabha Wardslaushttps://neveropen.dev
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments