Append value inside array of object

Hi!

How can I append new data to an array?

I have the following structure, and I need to update the value of the “lancamento” field How To?.

data": {
    "email": "email@email",
    "contas": [
      {
        "periodo": "2-2022",
        "lancamento": []
      },
      {
        "periodo": "3-2022",
        "lancamento": []
      }
    ]
  }

Thanks!

I found a way to do it. I only remove the current Array, I add the new information and save the Array again.

removeOld: Filter(
                      Select([0, "data", "contas"], Var("all")),
                      Lambda(
                        "entity",
                        Not(
                          Equals(
                            Select(["periodo"], Var("entity")),
                            Var("pData")
                          )
                        )
                      )
                    ),
                    newValue: Append(
                      [
                        {
                          periodo: Var("pData"),
                          lancamento: Append(
                            Var("valores"),
                            Select([0, "lancamento"], Var("periodo"))
                          )
                        }
                      ],
                      Var("removeOld")
                    ),
                    up: Update(Select([0, "ref"], Var("all")), {
                      data: { contas: Var("newValue") }
                    })
                  },
1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.