In D3 4.0, selection is no longer an array. According to the API:
Choosing to no longer subclass Array using prototype chain injection; they are now simple objects that improve performance.
So, if you are console.log(textLabels) , you will see something like this:
{_groups: Array[1], _parents: Array[1]}
Depending on what you choose. From there, you can access your array using textLabels._groups , for example.
To have an array, you should use selection.nodes() , which, according to the API:
Returns an array of all (non-null) elements in this selection.
Gerardo furtado
source share