Unique from Property in JSON

by Erik Bartlow

HTML

<h4>
Available Environments
</h4>
<ul id="test">

</ul>

JavaScript

var environments = {
  Message: 'Found 3 Environments.',
  Data: [{
      ID: 13,
      epr_id: 201919,
      Level: 'itg',
      Company: '',
      Type: 'app',
      Status: 'available',
      Size: '',
      Remarks: ''
    },
    {
      ID: 14,
      epr_id: 201919,
      Level: 'itg',
      Company: '',
      Type: 'db',
      Status: 'available',
      Size: '',
      Remarks: 'Reviewing to move'
    },
    {
      ID: 15,
      epr_id: 201919,
      Level: 'itg',
      Company: '',
      Type: 'web',
      Status: 'unavailable',
      Size: '',
      Remarks: ''
    },
    {
      ID: 16,
      epr_id: 201919,
      Level: 'pro',
      Company: '',
      Type: 'app',
      Status: 'available',
      Size: '',
      Remarks: ''
    },
    {
      ID: 17,
      epr_id: 201919,
      Level: 'pro',
      Company: '',
      Type: 'db',
      Status: 'available',
      Size: '',
      Remarks: ''
    },
    {
      ID: 18,
      epr_id: 201919,
      Level: 'pro',
      Company: '',
      Type: 'web',
      Status: 'unavailable',
      Size: '',
      Remarks: ''
    }
  ]
};

var environmentLevels = $.unique(environments.Data.map(function(d) {
  return d.Level;
}));
var environmentLevels2 = $.grep(environmentLevels, function(el, idx){
	return idx == $.inArray(el, environmentLevels);
})
$.each(environmentLevels2, function(index, value) {
  $('#test').append($('<li />').text(value));
});
//alert("There are " + environmentLevels.length + " environments.");