Richard Richard - 10 months ago 91
Javascript Question

d3.js: how to use map function?

How can I use
to get
[10, 12]
out of the following array?

var mydata = [
{ '__data__' : 10 },
{'__data__' : 12 }

I have been trying this, but it doesn't work:

var mymap =, function(d) {
return d.__data__;


You can't -- isn't for mapping a function across an array, but a shim for hashes. Briefly, while objects can be used like hashes, there are situations when unexpected behaviour can occur. A new Javascript standard proposes a solution to this, and until it is implemented, can be used to the same effect.

More information in the documentation.