[jQuery] jQuery Recursion/Iteration through JSON variable.

[jQuery] jQuery Recursion/Iteration through JSON variable.


Hi I would like to know if there is a simple way to show all elements
of that variable?
    var collectionElements = {
            teste: {
                var1: 'teste[]',
                var2: 'brincadeira-2',
                var3 : 'Elemento 2'
            },
            teste: {
                var1 : 'teste[]',
                var2 : 'brincadeira-3',
                var3 : 'Elemento 3'
            },
            teste: {
                var1 : 'teste[]',
                var2 : 'brincadeira',
                var3 : 'Elemento 1',
                teste: {
                    var1 : 'teste[]',
                    var2 : 'brincadeira-4',
                    3 : 'Elemento 4'
                }
            }
    };
I am tryin' to iterate all elements using this function (for debug
only)
    function iterateAllElements( elements ) {
        var ret = '';
         jQuery.each( elements, function( i,val ) {
             ret += ( typeof val == 'object') ? '\n Node ' + iterateAllElements
( val ) : i + ' : ' + val + ' / ';
         });
         return ret;
    };
With this function my firebug Console outputs only the last object
(3th node) with its child object.
Sorry my bad english! ^^