Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

107
Vistas
Loop through object javascript

This is my response body. I want to select only Collaborator's "supportNotifications" key-value set to true, how can I do that?

{
  "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
  }
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

This will give you each collaborator object that has supportNotification = true. Is this the result you are trying to select?

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);
about 4 years ago · Juan Pablo Isaza Denunciar

0

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);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda