In D3 4.0, selections are not arrays anymore. According to the API:
Selections no longer subclass Array using prototype chain injection; they are now plain objects, improving performance.
So, if you console.log(textLabels)
, you're gonna see something like this:
{_groups: Array[1], _parents: Array[1]}
Depending on exactly what are you selecting. From there, you can access your array using textLabels._groups
, for instance.
For having an array, you have to use selection.nodes()
, which, according to the API:
Returns an array of all (non-null) elements in this selection.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…