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

403
Vistas
How can I get the value of a sibling key in a javascript object?

I have the following object and want to grab the "payroll_run_items" where month equals "2022-04-01" so s.th. like the value of a sibling key where key values Foo.

{
  "payrollRuns": [
    {
      "company": {
        "id": 1,
        "name": "Example Ltd.",
        "country": "Germany",
        "city": "Munich",
        "zip": "80801",
        "street": "Max-Strasse",
        "house_number": "3",
        "vat": "DE12434",
        "customer_number": "1",
        "fee_offer": "59.00",
        "is_active": true
      },
      "month": "2022-06-01",
      "amount": "733.00",
      "line_items": 1,
      "payroll_run_items": []
    },
    {
      "company": {
        "id": 1,
        "name": "Example Ltd.",
        "country": "Germany",
        "city": "Munich",
        "zip": "80801",
        "street": "Max-Strasse",
        "house_number": "3",
        "vat": "DE12434",
        "customer_number": "1",
        "fee_offer": "59.00",
        "is_active": true
      },
      "month": "2022-04-01",
      "amount": "7570.02",
      "line_items": 2,
      "payroll_run_items": [
        "{amount: \"3749.00\", id: 68, month: {…}, offer: {…},…}",
        "{amount: \"3821.02\", id: 73, month: {…}, offer: {…},…}"
      ]
    }
  ],
  "setPayrollRuns": "ƒ bound dispatchSetState() {}"
}

All I came up with so far is to get all keys but how would I now check for "2022-04-01" and assign the "payroll_run_items" to a variable?

const payrollLineItems = () => (
        Object.keys(props.payrollRuns)
    )
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

find the object where the month matches the condition, and extract the property value you want.

const data={payrollRuns:[{company:{id:1,name:"Example Ltd.",country:"Germany",city:"Munich",zip:"80801",street:"Max-Strasse",house_number:"3",vat:"DE12434",customer_number:"1",fee_offer:"59.00",is_active:!0},month:"2022-06-01",amount:"733.00",line_items:1,payroll_run_items:[]},{company:{id:1,name:"Example Ltd.",country:"Germany",city:"Munich",zip:"80801",street:"Max-Strasse",house_number:"3",vat:"DE12434",customer_number:"1",fee_offer:"59.00",is_active:!0},month:"2022-04-01",amount:"7570.02",line_items:2,payroll_run_items:['{amount: "3749.00", id: 68, month: {…}, offer: {…},…}','{amount: "3821.02", id: 73, month: {…}, offer: {…},…}']}]};

const out = data.payrollRuns.find(obj => {
  return obj.month === '2022-04-01';
}).payroll_run_items;

console.log(out);

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