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?
catalog1.catalog2, it returns product A, not B.for (r in catalog1)is not the correct way to iterate over an array.