Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

417
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda