NickBraunagel
NickBraunagel

Reputation: 1599

D3.js selection.data() optional parameters

Per D3 v4 documentation, function syntax for data() is given as selection.data([data[, key]]).

This suggests to me data AND key are optional parameters for data(). But wouldn't data always be a required parameter? I know key is optional and defaults to the array index if not specified - but why would the data parameter ever be optional, what is the point of binding nothing to DOM elements?

Upvotes: 0

Views: 139

Answers (1)

Mark
Mark

Reputation: 108567

All arguments to .data are optional. From the docs:

If data is not specified, this method returns the array of data for the selected elements.

Further, it is written as [data[, key]] because when data is specified key then becomes an optional parameter.

Upvotes: 2

Related Questions