Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <script>
    (function() {
      var myobj = {
        obj1: { key1: 'val1', key2: 'val2' },
        obj2: { key1: '2val1', 
               key2: { nest1: 'val1', nest2: 'val2', nest3: 'val3' }, 
               key3: { nest1: 'K3val1', nest2: 'K3val2', 
                      nest3: [
                        { nest1: 'val1', nest2: 'val2', nest3: 'val3' }, 
                        { nest1: 'val1', nest2: 'val2', nest3: 'val3' }
                      ]
                     }
              },
        obj3: { key1: 'dddddval1', key2: 'val2' }
      };    
      
      var path = "";
  
      // Loop the top level
      $.each(myobj, walker);
  
      function walker(key, value) {
          var savepath = path;
  
          path = path ? (path + "." + key) : key;
        
          display("Visiting " + path);
  
          // ...do what you like with `key` and `value`
  
          if (typeof value === "object") {
              // Recurse into children
              $.each(value, walker);
          }
  
          path = savepath;
      }
      
      function display(msg) {
        var p = document.createElement('p');
        p.innerHTML = String(msg);
        document.body.appendChild(p);
      }
    })();
  </script>
</body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers