Este es mi cuerpo de respuesta. Quiero seleccionar solo el valor-clave "supportNotifications" de Collaborator establecido en verdadero, ¿cómo puedo hacerlo?
{ "status": true, "date": "2022-04-06T16:33:13.630Z", "data": { "collaborators": [ { "name": "Paul", "lastCheckin": "2022-03-31T19:54:50.584Z", "sales": 1, "createdAt": "2022-03-30T14:47:48.478Z", "id": "62446d4ab7f4da001e8f40dc", "supportNotification": true, "collaboratorId": 1 }, { "name": "John", "lastCheckin": null, "sales": 0, "createdAt": "2022-03-01", "id": "62446ea4b7f4da001e8f40df", "supportNotification": false, "collaboratorId": 6 } ], "count": 2 } }Esto le dará cada objeto colaborador que tenga supportNotification = true. ¿Es este el resultado que está tratando de seleccionar?
var body = { status: true, date: "2022-04-06T16:33:13.630Z", data: { collaborators: [ { name: "Paul", lastCheckin: "2022-03-31T19:54:50.584Z", sales: 1, createdAt: "2022-03-30T14:47:48.478Z", id: "62446d4ab7f4da001e8f40dc", supportNotification: true, collaboratorId: 1, }, { name: "John", lastCheckin: null, sales: 0, createdAt: "2022-03-01", id: "62446ea4b7f4da001e8f40df", supportNotification: false, collaboratorId: 6, }, ], count: 2, }, }; var result = []; body.data.collaborators.forEach((item) => { if (item.supportNotification === true) { result.push(item); } }); console.log(result);let response = { "status": true, "date": "2022-04-06T16:33:13.630Z", "data": { "collaborators": [ { "name": "Paul", "lastCheckin": "2022-03-31T19:54:50.584Z", "sales": 1, "createdAt": "2022-03-30T14:47:48.478Z", "id": "62446d4ab7f4da001e8f40dc", "supportNotification": true, "collaboratorId": 1 }, { "name": "John", "lastCheckin": null, "sales": 0, "createdAt": "2022-03-01", "id": "62446ea4b7f4da001e8f40df", "supportNotification": false, "collaboratorId": 6 } ], "count": 2 } }; const collaborators = response.data.collaborators.filter(c => c.supportNotification);