按对象键和值对过滤对象数组

时间:2019-07-23 14:03:24

标签: javascript

我不能为从对象数组中获取数据而费心。 我有数据

const initData = [{ index: "1", buildingNo: "P11 A", floor: "parter", areaVolume: "64,32", gardenOrAttic: "ogródek", gardenOrAtticVolume: "12", price: "236500", blueprint: "true", status: "sprzedany" },
{ index: "2", buildingNo: "P11 B", floor: "piętro", areaVolume: "75,00", gardenOrAttic: "ogródek", gardenOrAtticVolume: "85", price: "486500", blueprint: "true", status: "sprzedany" },
{ index: "3", buildingNo: "P12 A", floor: "parter", areaVolume: "64,32", gardenOrAttic: "strych", gardenOrAtticVolume: "99", price: "256500", blueprint: "true", status: "wolny" },
{ index: "4", buildingNo: "P12 B", floor: "parter", areaVolume: "60,00", gardenOrAttic: "strych", gardenOrAtticVolume: "19", price: "286500", blueprint: "true", status: "sprzedany" },
{ index: "5", buildingNo: "P13 A", floor: "piętro", areaVolume: "45,00", gardenOrAttic: "ogródek", gardenOrAtticVolume: "78", price: "716500", blueprint: "true", status: "rezerwacja" }];

而且我不知道如何返回具有多个属性的结果。 我正在动态创建一个包含键和值绑定对象的对象

let filterBy = {status: "wolny", floor:"piętro"}

我想将filterBy.key(statys and floor)initData匹配并返回包含正确值(status == wolny and floor == piętro)的对象

我设法写了一些仅对一对键值有效的代码。 不知道如何针对多个属性

initData.forEach(data => {
    if(data[Object.keys(filterData)] == Object.values(filterData)) {
        console.log("true")
    } else {
        console.log("false")
    }
});

0 个答案:

没有答案