Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

D3.js bisector.left() Method

  • Last Updated : 23 Sep, 2020

With the help of bisector.left() method, we can insert the element in the sorted array in such a way that if the value in the array is equal to or greater than the element to be inserted than will insert in the left of the present element by using this method.


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!

bisector.left(arr, ele)

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

  • arr: It is the array passed as parameter.
  • ele: It is the value to be inserted.

Return Value: It return the index of newly inserted element.

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 bisector.left() method, we are able to get the index of element which is to be inserted at the left of the sorted array.

// Defining d3 contrib variable  
var d3 = require('d3');
var bisect = d3.bisector(i =>
var gfg = bisect.left([1, 2, 3, 4, 5], 3)



Example 2:

// Defining d3 contrib variable  
var d3 = require('d3');
var arr = []
for(var i = 0; i < 5; i++) {
var bisect = d3.bisector(i => i.float)
var gfg = bisect.left(arr, 3)


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!