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>
  <script>
    (function() {
      var yourObject = {
        "result": [
            {
                "category": "Negative Notification",
                "event": "open",
                "result": 2
            },
            {
                "category": "Referral",
                "event": "bounce",
                "result": 1
            },
            {
                "category": "Negative Notification",
                "event": "delivered",
                "result": 34
            },
            {
                "category": "Negative Notification",
                "event": "processed",
                "result": 34
            },
            {
                "category": "Positive Notification",
                "event": "open",
                "result": 42
            },
            {
                "category": "Referral",
                "event": "delivered",
                "result": 17
            },
            {
                "category": "Positive Notification",
                "event": "processed",
                "result": 504
            },
            {
                "category": "Referral",
                "event": "processed",
                "result": 18
            },
            {
                "category": "Positive Notification",
                "event": "delivered",
                "result": 504
            },
            {
                "category": "Negative Notification",
                "event": "bounce",
                "result": 16
            },
            {
                "category": "Positive Notification",
                "event": "bounce",
                "result": 176
            },
            {
                "category": "Referral",
                "event": "open",
                "result": 10
            }
        ]
      };
      
      // The object that will contain the result
      var obj = {};
      
      // Loop through the `result` array on your object
      yourObject.result.forEach(function(element) {
        // See if we already have an entry for that category
        var entry = obj[element.category];
        if (!entry) {
          // We don't, so create a blank array for it
          entry = obj[element.category] = [];
        }
        
        // Push this entry in the category's array
        entry.push(element);
      });
      
      display("obj['Negative Notification'].length = " +
              obj['Negative Notification'].length);
      
      function display(msg) {
        var p = document.createElement('p');
        p.innerHTML = String(msg);
        document.body.appendChild(p);
      }
    })();
  </script>
</body>
</html>
Output 300px

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

Dismiss x
public
Bin info
anonymouspro
0viewers