Objects
Object is a container for named values called properties. The variables that an object holds can be of any data type and these variables can be read from and written to after the initial object creation, and you can also add more variables to an object after it has been created.
Example of an (stringified) object called person
:
{
"firstName": "John",
"lastName": "Doe",
"age": 50,
"eyeColor": "blue"
};
Creates a new empty object. Does nothing if the object already exists.
Box Name | Type | Description |
---|---|---|
New Object Name | String | Name for your new object |
Create a new object key or change a value inside an existing key.
Supports setting the values to objects/arrays without having to parse and stringify them.
Box Name | Type | Description |
---|---|---|
Object Name | String | Name of the object you want to access |
Key | String | The name of the new or existing key |
Variable/Number/String | Value to associate with the key |
Retrieves a value associated with the specified object key.
Box Name | Type | Description |
---|---|---|
Object Name | String | Name of the object you want to access |
Key | String | The name of the key containing the value |
Save Variable As | String | Variable name to save the object key value |
Retrieves the first object key. You can use this command together with Object Get Next Key to iterate over all object keys.
Unlike in some other languages, object keys are not sorted and their order is not guaranteed.
Box Name | Type | Description |
---|---|---|
Object Name | String | Name of the object you want to access |
Save Variable As | String | Variable name to save the retrieved key into |
Retrieves the next object key. You can use this command together with Object Get First Key to iterate over all object keys.
Unlike in some other languages, object keys are not sorted and their order is not guaranteed.
Box Name | Type | Description |
---|---|---|
Object Name | String | Name of the object you want to access |
Key | String | Object key to continue to iterate from |
Save Variable As | String | Variable name to save the retrieved key into |
Gets a size of an object, i.e. how many keys the object contains.
Box Name | Type | Description |
---|---|---|
Object Name | String | Name of the object you want to check |
Save Variable As | String | Variable name to save the object size |
Returns a JSON string of the whole object.
You can use this command together with File: Save String command to save the whole object into a file. Once loading it back from the file, you can use Parse Array/Object command to turn the JSON string back into the original object.
Stringifies a whole button if you leave the Object Name
box empty or set it to local
for the current button, or put in the button ID you wish to stringify.
Box Name | Type | Description |
---|---|---|
Save Variable As | String | Variable to save the JSON string of the object into |
Object Name | String | Name of the object to stringify |
Turns a JSON string into an array/object. Must be properly formatted (SAMMI will give you a warning if it finds any formatting errors).
This way you can easily create a prepopulated object/array, as it supports nesting.
Read more about JSON syntax at w3schools.com.
Box Name | Type | Description |
---|---|---|
Array/Object Name | String | Name of the variable to save the parsed array/object into |
String Array/JSON | JSON String | JSON string to parse |
JSON string before conversion | Result saved in the variable |
---|---|
|
|
|
Converts the keys or values of an object into an array.
Box Name | Type | Description |
---|---|---|
Conversion Type | Dropdown | Convert keys or values into the array. |
Object Name | String | Name of the object to extract the keys or values. |
Array Name | String | Name of the array to save the keys or values. |
Conversion Type | Object | Result |
---|---|---|
Keys | {“name”:”SAMMI”, “likes”:20000} | [“likes”,”name”] |
Values | {“name”:”SAMMI”, “likes”:20000} | [20000,”SAMMI”] |