title: Count specific key in json jquery
body: <pre><code>[
      {
          color: "red",
          value: "#f00"
      },
      {
          color: "green",
          value: "#0f0"
      },
      {
          color: "blue",
          value: "#00f"
      },
      {
          color: "cyan",
          value: "#0ff"
      },
      {
          color: "magenta",
          value: "#f0f"
      },
      {
          color: "yellow",
          value: "#ff0"
      },
      {
          color: "black",
          value: "#000"
      }
  ]
  </code></pre>
  
  <p>Counting json key varies from </p>
  
  <pre><code>function count(obj) {
     var count=0;
     for(var prop in obj) {
        if (obj.hasOwnProperty(prop)) {
           ++count;
        }
     }
     return count;
  }
  </code></pre>
  
  <p>to </p>
  
  <pre><code>var keys = [];
  $.each(data, function(key, value) {
    keys.push(key)
  });
  // numberOfKeys should equal to 2
  var numberOfKeys = keys.length;var keys = [];
  $.each(data, function(key, value) {
    keys.push(key)
  });
  // numberOfKeys should equal to 2
  var numberOfKeys = keys.length;
  </code></pre>
  
  <p>But what if i have a specific key that i only need to count like in my sample count the number of <code>color</code> or count the number of 'red'.</p>
  
  <ol>
  <li><p>Count the number of existing (specific) key <code>Example count color</code></p></li>
  <li><p>Count the number of existing (specific) value <code>Example count red</code></p></li>
  </ol>