How to add keyed array fields to Array component or populate keyed array in Session Storage?

I have an array within my Session Storage named Response with two fields (Question and Answer).

image

There isn’t a way to add to the array fields in Session Storage, it only has a Set action.

The Array component does have additional actions like Add item, but there doesn’t appear to be a way to add fields to the array, so what’s the best way to populate the array in Session Storage?

I tried @ben’s solution, but the syntax for populating the array doesn’t work.

I am able to get it to populate the array with a static values

[{"Question":"CompanySize","Answer":"value"}]

I cannot figure out how to add dynamic values. I’ve tried the follow way, without success:
. [{"Question":"{{steppersurveyv2.companysizequestion1.value}}","Answer":"{{steppersurveyv2.radiogroup.companysize0110.value}}"}]

An ugly solution would be:

  1. Having a custom formatter to push an element to an array: (I don’t know if such functionality is already present in Wappler, I haven’t learned anything about the new Array functions in Wappler)
exports.push = function (arr, item) {
    arr.push(item);
    return arr;
}
  1. In Set Session Storage Item (your 2nd screenshot), in the Value expression, select the existing Response array, plus .push(new_item), this will return a new array with the new object contained in it (as well as the previous elements)

I have the same issue in my app, and I have two different data stores, one for the contacts and one for the questions/ answers… and they are linked by a contact_id field common to each.

I got it to work thanks to this bug report. You don’t need to go to Array first, you can populate the keyed array in the Local Storage directly after getting past the bug that doesn’t show the fields in the array.