Accepted answer

The key function doesn't change the underlying data, it just tells D3 how to extract the identifying attribute -- each datum (in the data passed to .data() and bound to the DOM elements) will be passed into the key function, the return value will be used to match up elements (i.e. those for which the same value is returned for both DOM element and datum).

If you change key functions when updating, the computed selections will change accordingly. That's all there is to it.

Related Query