The Variable object
Create Variable objects to store data within a Retool app. Each instance has a unique name with which to reference (e.g., myVariable1.value
).
Properties
id
string
The name of the variable object.
value
object[]
The data stored in the variable object.
Methods
Methods for interacting with variables. You can write JavaScript almost anywhere in Retool and use methods to manipulate data or components.
setIn()
Sets the value of the specified variable at a specified location. The initial value must be an empty object (e.g., { }
). Returns a void Promise
when the method resolves.
path
requiredarray
A list of keys or indexes for the path of the object to update.
value
requiredany
The value to set at the specified path.
Example
In variable1
, set the second item of key1
, nested in object1
, to value2
.
await variable1.setIn(["object1", "key1", 1], "value2");
setValue()
Sets the value of a variable. Returns a void Promise
when the method resolves.
value
requiredany
The value to set.
Example
Set the value of variable1
to the value of usersTable.sort
.
await variable1.setValue(usersTable.sort);