Category: How do I do X?


This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

How to store (and add to) an array in storeValue()?


I am trying to create an array of integers and store it in Appsmith store, but I am experiencing unexpected behavior. When trying to add more values to the array, it pushes into an empty one. I also have trouble resetting the stored variable after passing data into my database via a query. It seems that Appsmith checks the session store first and returns that value by default, which caused confusion. Thanks to the Appsmith team's guidance, I now understand how to use the storeValue function correctly and differentiate between persistent and session stores.


The user was experiencing unexpected behavior when trying to create and modify an array in Appsmith's store. They were initially pushing values to the array, but later found that the array was empty when trying to access it. The issue was due to the asynchronous nature of the storeValue function, which required the use of the await keyword. They were also not correctly adding elements to the array using the Array.push method.

The user also encountered an issue when trying to clear a stored variable using storeValue('myVar', undefined). The issue was that Appsmith checks the session store before the persistent store, so if a variable with the same name exists in the session store, it will return that value instead of the one in the persistent store. To resolve this issue, they needed to refresh the page to clear the session store or use a different variable name.

The solution involved using the await keyword with storeValue, correctly adding elements to the array, and understanding the difference between the session and persistent store in Appsmith's storage. The user was able to resolve their issues with the help of the Appsmith team's guidance and code examples.