d3.js: how to use map function?

后端 未结 2 1042
太阳男子
太阳男子 2021-02-19 10:36

How can I use d3.map() to get [10, 12] out of the following array?

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


        
2条回答
  •  庸人自扰
    2021-02-19 11:08

    You can't -- d3.map() 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, d3.map() can be used to the same effect.

    More information in the documentation.

提交回复
热议问题