Q:

A javascript filter using a for/in loop?

Is it possible to filter a javascript array? I've taken the following approach but it doesn't seem to produce the intended results.
Arrays:
var catalog1 = [0]
var catalog2 = [1]
var products = [{ id: "PRODUCTA", desc: "Toys" },
                { id: "PRODUCTB", desc: "Cars" }]

Filter:
var NewProducts = [];
for (r in catalog1) NewProducts.push(products[r]);

NewProducts should contain either product A or B depending on which catalog array is selected. My attempt always return product A, as in r = 0. What am I missing?
http://jsfiddle.net/rE52f/

A:

It is because Javascript's for each loop generates the keys of your collection. You will have to change it to: 
for (var r in someCatalogue) NewProducts.push(products[someCatalogue[r]]);

You can also use map inside a closure, if you don't have to support IE8 and less:
(function(products) {
  NewProducts = someCatalogue.map(function(item) { return products[item]; });
})(products);

