Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  
</body>
</html>
 
console.log(flatten({
  'foo': {
    'bar': 'baz',
    'hello': { 'world': 3 },
    'qux': ['wibble', 'wobble', 'wubble']
  },
  'howdy': 'there',
  'javascript': { 'is': { 'easy': { 'as': ['ABC', 123] } } },
  'meaning': 42
}));
console.log(flatten({
  'index': {
    'about': {
      'team': true,
      'company': ['Jim', 'Barry']
    }
  }
}));
function flatten (nested) {
  var urls = {};
  flatten(nested);
  return urls;
  function flatten (obj, currentPath) {
    for (var key in obj) {
      if (obj.hasOwnProperty(key)) {
        var prop = obj[key], path = currentPath ? currentPath + '/' + key : key;
        if (typeof prop != 'object' || Array.isArray(prop)) {
          urls[path] = prop;
        } else {
          flatten(prop, path);
        }
      }
    }
  }
}
Output

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

Dismiss x
public
Bin info
jcreadypro
0viewers