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

141
Vistas
how to filter object of arrays based on inner object column condition

I have the following object and i want to only get the first row that is row with Number (rowNumber: 1) The criteria is that "columnId": 8505590182897540 should have its value equal to Open and "columnId": 7009559238731652 should have its value not exist.

  output =  { "rows": [
        {
            "id": 1844195940165508,
            "rowNumber": 1,

            "cells": [
                {
                    "columnId": 8505590182897540,
                    "value": "Open",
                    "displayValue": "Open"
                },
                {
                    "columnId": 7009559238731699,
                    "value": "Steep",
                    "displayValue": "Steep"
                },
                {
                    "columnId": 7009559238731652
                }
            ]
        },
        {
            "id": 1844195940165509,
            "rowNumber": 2,

            "cells": [
                {
                    "columnId": 8505590182897540,
                    "value": "Open",
                    "displayValue": "Open"
                },
                {
                    "columnId": 7009559238731699,
                    "value": "Steep",
                    "displayValue": "Steep"
                },
                {
                    "columnId": 7009559238731652,
                    "value": "Field has value",
                    "displayValue": "Field has value"
                }
            ]
        }
    ]
}

I am able to loop through the rows with the following code and filter based on the cell.value = Open" and add the result to a list, but how can i check for each cell based on the columnid '8505590182897540' if the value =="Open" and the columnid '7009559238731652' where value is blank and add that row id to the list?

this is the code i have so far

var emptyArray = [];
output.rows.map(function (row) {
    row.cells.forEach(function (cell) {
          if (cell.value == 'Open') {
              emptyArray.push(row.id);
          }
      })
    });
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You could define filters for cell objects and check all filters.

const
    data = [{ id: 1844195940165508, rowNumber: 1, cells: [{ columnId: 8505590182897540, value: "Open", displayValue: "Open" }, { columnId: 7009559238731699, value: "Steep", displayValue: "Steep" }, { columnId: 7009559238731652 }] }, { id: 1844195940165509, rowNumber: 2, cells: [{ columnId: 8505590182897540, value: "Open", displayValue: "Open" }, { columnId: 7009559238731699, value: "Steep", displayValue: "Steep" }, { columnId: 7009559238731652, value: "Field has value", displayValue: "Field has value" }] }],
    filters = [
        { columnId: 8505590182897540, value: 'Open' },
        { columnId: 7009559238731652, value: undefined }
    ],
    result = data.filter(({ cells }) => filters.every(f => cells.some(c =>
        c.columnId === f.columnId &&
        c.value === f.value
    )));

console.log(result);

about 4 years ago · Juan Pablo Isaza Denunciar

0

Map the rows, within the map lambda filter the desired cells. Something like:

const filterCells = v => 
  v.columnId === 8505590182897540 && v.value === `Open` ||
  v.columnId === 7009559238731652 && !v.value;
const filtered = values().rows.map(v => 
  ( {id: v.id, cellsFound: v.cells.filter(filterCells)} ));

console.log(`if you only need ids: ${filtered.map(v => v.id)}`);
console.log(filtered);

function values() {
  return {
    "rows": [{
        "id": 1844195940165508,
        "rowNumber": 1,

        "cells": [{
            "columnId": 8505590182897540,
            "value": "Open",
            "displayValue": "Open"
          },
          {
            "columnId": 7009559238731699,
            "value": "Steep",
            "displayValue": "Steep"
          },
          {
            "columnId": 7009559238731652
          }
        ]
      },
      {
        "id": 1844195940165509,
        "rowNumber": 2,

        "cells": [{
            "columnId": 8505590182897540,
            "value": "Open",
            "displayValue": "Open"
          },
          {
            "columnId": 7009559238731699,
            "value": "Steep",
            "displayValue": "Steep"
          },
          {
            "columnId": 7009559238731652,
            "value": "Field has value",
            "displayValue": "Field has value"
          }
        ]
      }
    ]
  };
}
.as-console-wrapper {
  max-height: 100% !important;
}

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