title: Javascript: filter array of objects by array of strings
body: <p>I wonder if there is a more elegant way of doing this. Suppose i have an array of objects like this:</p>
  
  <pre><code>a = [
    {
      "id": "kpi02",
      "value": 10
    },
    {
      "id": "kpi02",
      "value": 30
    },
    {
      "id": "kpi02",
      "value": 11
    },
    {
      "id": "kpi02",
      "value": 33
    },
    {
      "id": "kpi03",
      "value": 1
    },
    {
      "id": "kpi03",
      "value": 0.5
    },
    {
      "id": "kpi04",
      "value": 0.5
    }
  ]
  </code></pre>
  
  <p>Now i want to filter on the <code>id</code> property, to return all objects with a match in another array </p>
  
  <pre><code>var kpis = ["kpi03", "kpi02"];
  </code></pre>
  
  <p>I came up with this solution:</p>
  
  <pre><code>var b = [];
  for (j in kpis) {
   for (i in a) { 
      if (a[i].id == kpis[j]) {
      b.push(a[i]);
      }
   }
  }
  </code></pre>
  
  <p>Coming from R, this seems a bit complicated, is there any way to do that with the <code>filter</code> prototype? Like this but with an array of strings to compare with instead of a single string:</p>
  
  <pre><code> var b = a.filter( function(item){return (item.id == "kpi03");} );
  </code></pre>
  
  <p>Thanks a lot!</p>