Create an array of all form inputs that are 'true'

Hi all,

I am looking for some advice on the simplest way to create an array of checkbox ids that equate to 'true'.

I have a constructed a layout of checkboxes so the user can select the months against which they want to run an API query.

The checkbox id's are set as follows:

January 2021 = '0121'
February 2021 = '0221'
March 2021 = '0321'
....
December 2021 = '1221'
January 2022 = '0122'

I'm looking to return something along the lines of ....

{
0: "0321",
1: "0521",
2: "0522",
3: "0822",
4: "0922",
5: "0323",
...which can then be iterated over for the API interaction.

I have tried a number of filter operations on the data but keep getting Retool errors.

Really appreciate any suggestions!

Thanks.

Object.keys(form1.data).filter(key => form1.data[key] === true)

Worked an absolute treat - thanks so much for the help!

just a friendly reminder to mark his reply as the solution for anybody in the future w the same or similar question to easily find the answer =)

2 Likes