所以,我有一个名为 products 的对象,它有 3 个属性:
var products = [
{"name":"product1","size":"large","color":"blue","gender":"male"},
{"name":"product2","size":"small","color":"pink","gender":"female"},
{"name":"product3","size":"large","color":"green","gender":"male"},
{"name":"product4","size":"large","color":"yellow","gender":"female"},
{"name":"product5","size":"medium","color":"blue","gender":"female"},
{"name":"product6","size":"large","color":"green","gender":"male"},
{"name":"product7","size":"small","color":"yellow","gender":"male"},
{"name":"product8","size":"medium","color":"red","gender":"female"},
{"name":"product9","size":"large","color":"blue","gender":"male"},
{"name":"product10","size":"small","color":"red","gender":"female"}
];
那么,如果我有3个尺寸、颜色和性别选择框,我将如何过滤这 3 个以获得产品名称?
我正在尝试在 javascript 中使用 .filter 。我知道如何在非关联数组中使用它。但是,关联数组呢?你如何使用它们?