Angular 5 - 在数组中查找对象并使用找到的对象创建新数组
Angular 5 - Find objects in array and create new array with those objects found
我有以下对象数组。我试图用 type “noActiveServiceDashboard” 和 type “extraAmountDashboard 找到对象" 并以 相同的格式 创建一个新的对象数组,仅包含这两个条目。
我试过使用 .find() 或 .filter() 但我无法访问其中的属性。
cmsContentModules: Array<{}>
let filteredModules: Array<{}> = cmsContentModules;
filteredModules
(5) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0: {cid: "2462437627203", tipo: "Funcional", Titulo: "bannerDashboard", type: "bannerDashboard", literalTitle: "Jazztel rápido y fácil", …}
1: {cid: "2462444315058", tipo: "Funcional", Titulo: "noActiveServiceDashboard", type: "noActiveServiceDashboard", literalTitle: "Hola", …}
2: {cid: "2462396510226", tipo: "Funcional", type: "dashboardLineSelector", idCmsLinkItems: "2462397143052", literalErrorSubtitle: "No se puede cambiar el servicio activo", …}
3: {cid: "2462396519886", tipo: "Funcional", type: "extraAmountDashboard", gasto: "Gasto extra:", idCmsLinkDetailedUsagePage: "2462417671130", …}
4: {cid: "2462396619049", tipo: "ArrayModulos", ModulosArray: Array(14), type: "consumptionsCounters"}
length: 5
__proto__: Array(0)
我知道如何使用 .filter()
filteredModules.filter(
module =>
module["type"] === "noActiveServiceDashboard" || module["type"] === "dashboardLineSelector"
);
您可以访问变量,将您搜索的值的键放在 [] 之间。
我有以下对象数组。我试图用 type “noActiveServiceDashboard” 和 type “extraAmountDashboard 找到对象" 并以 相同的格式 创建一个新的对象数组,仅包含这两个条目。
我试过使用 .find() 或 .filter() 但我无法访问其中的属性。
cmsContentModules: Array<{}>
let filteredModules: Array<{}> = cmsContentModules;
filteredModules
(5) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0: {cid: "2462437627203", tipo: "Funcional", Titulo: "bannerDashboard", type: "bannerDashboard", literalTitle: "Jazztel rápido y fácil", …}
1: {cid: "2462444315058", tipo: "Funcional", Titulo: "noActiveServiceDashboard", type: "noActiveServiceDashboard", literalTitle: "Hola", …}
2: {cid: "2462396510226", tipo: "Funcional", type: "dashboardLineSelector", idCmsLinkItems: "2462397143052", literalErrorSubtitle: "No se puede cambiar el servicio activo", …}
3: {cid: "2462396519886", tipo: "Funcional", type: "extraAmountDashboard", gasto: "Gasto extra:", idCmsLinkDetailedUsagePage: "2462417671130", …}
4: {cid: "2462396619049", tipo: "ArrayModulos", ModulosArray: Array(14), type: "consumptionsCounters"}
length: 5
__proto__: Array(0)
我知道如何使用 .filter()
filteredModules.filter(
module =>
module["type"] === "noActiveServiceDashboard" || module["type"] === "dashboardLineSelector"
);
您可以访问变量,将您搜索的值的键放在 [] 之间。