Extacting Objects from JSON

Making a String from the JSON using AngularJS.

by Rittam Debnath

HTML

<div ng-app="loop" ng-controller="loopCtrl">
  <p>
    {{dump}}
  </p>

</div>

JavaScript

angular.module('loop', [])

.controller('loopCtrl', ['$scope', function($scope) {
  $scope.dump = [];
  $scope.jsonVar = {
    "Standard": {
      "2": {
        "val": 3,
        "letter": "H"
      },
      "3": {
        "val": 4,
        "letter": "H"
      },
      "4": {
        "val": 5,
        "letter": "H"
      },
      "5": {
        "val": 6,
        "letter": "H"
      }
    }
  };
  var obj = $scope.jsonVar;
  angular.forEach(obj, function(v, k) {
    angular.forEach(v, function(v, k) {
      angular.forEach(v, function(v, k) {
      	$scope.dump.push(v);
      });
    });
  });
  
  $scope.dump = $scope.dump.join('').match(/[\s\S]{1,2}/g) || [];
  console.log($scope.dump.join(', '));
}]);