How to add a key/value pair to an existing list?

Hi,

from my database I get the Name and Age fields of my users into a data variable. To handle the data in the app I would like to add a boolean field Editing to each of my users.

How to add a key/value pair to an existing list? Or specific in this case: How can one create a list with Name, Age, Editing? To start with Editing should be set to false.

Thank you and best regards,

Joerg

Hello Joerg,

MAP(data.Users, {name: item.name, age: item.age, editing: false}) gives you a new list with editing set to false for each item. To understand MAP, you can check the docs. :slight_smile:

Thanks @Mari

works like a charm :slight_smile:

I did read the docs but this didn’t reveal itself to me. I got hung up on the term ‘Transform formula’. Perhaps you could include an example with the Transform formula with multiple keys.

Thank you and best regards,

Joerg

Great! MAP applies the specified transform formula to each of the items in the list.

For example, if your users list had separate firstName and lastName fields, MAP(data.Users, {fullName: item.firstName + " " + item.lastName}) transforms the original input list into a new list that only has their full names.

With this formula, a list like data.Users = [{firstName: "Jack", lastName: "Green"}, {firstName: "Mary", lastName: "White"}] would be transformed into [{fullName: "Jack Green"}, {fullName: "Mary White"}]