How to loop through all the nodes and its keys and text in a diagram?

I have a palette and from palette suppose I dragged multiple nodes on to my diagram.
Now I want to loop through all the nodes and its text and key property value for my condition to become true and if that happens I want to call some function.

So my question is how to loop through all the nodes in my diagram?
Please help asap.

Thanking in Anticipation.

Note: Using latest version of goJS

myDiagram.nodes.each(function(n) {
    if (n.data.text ... && n.data.key ...) { ... do something ... }
});

You might also want to consider calling Diagram.findNodesByExample.

Generally useful information is also at: http://gojs.net/latest/intro/collections.html

Great. Thanks a Lot.!