Set
The `Set` object stores unique values of any type, whether primitive values or object references. The Set is used as storage for all multi-value objects in this API: custom fields that store multiple values, issue links, issues in a project, and so on. You can access single values in the collection directly (see first(), last(), get(index)), use an iterator (see entries(), values()), or traverse with forEach(visitor) and find(predicate) methods. The workflow API is based on ECMAScript 5.1. This Set implementation mimics the functionality supported by the ES 6 Set interface.
Properties
Name | Type | Description |
---|---|---|
added | Set | The elements that are added to a field that stores multiple values in the current transaction. Only relevant when the Set represents a multi-valued property (field) of a persistent entity. |
isChanged | boolean | When the Set represents a multi-valued property (field) of a persistent entity and the field is changed in the current transaction, this property is `true`. |
removed | Set | The elements that are removed from a field that stores multiple values in the current transaction. Only relevant when the Set represents a multi-valued property (field) of a persistent entity. |
size | number | The number of elements in a Set. Use thoughtfully, as the calculation for large collections (like `project.issues`) may be resource consumptive. |
Methods
add
Add an element to a Set. If the specified value is already present, a duplicate value is not added.
Parameters
Name | Type | Description |
---|---|---|
element | Object | The element to add to the Set. |
clear
Remove all of the values from a Set.
delete
Remove an element from a Set. If the specified element is not present, nothing happens.
Parameters
Name | Type | Description |
---|---|---|
element | Object | The element to remove from the Set. |
entries
Get an iterator for the entries in a Set. The same as `values()`. Use an iterator when you need to traverse over entries until a specific condition is met and modify the entries at the same time.
Return Value
Type | Description |
---|---|
Iterator.<Object> | An iterator for the collection of values. |
Example
See Also
If you need to modify all of the elements in the Set, see forEach(visitor).
If you need to find an element that meets specific criteria, see find(predicate).
find
Find the first element in a Set for which a predicate function returns `true`.
Parameters
Name | Type | Description |
---|---|---|
predicate | function | A function with one argument that returns either true or false for a given value in the Set. |
Return Value
Type | Description |
---|---|
Object | The first value that returns `true` for the predicate function or undefined. |
Example
first
Find the first object in a collection based on the order in which the elements were added to the Set.
Return Value
Type | Description |
---|---|
Object | The first object in a collection or null if the collection is empty. |
forEach
Apply a visitor function to each member of a collection.
Parameters
Name | Type | Description |
---|---|---|
visitor | function | The function to be applied to each member of the collection. |
Example
get
Find an element with a specific index position in a Set.
Parameters
Name | Type | Description |
---|---|---|
index | number | The ordinal index of the element to be returned from the Set. |
Return Value
Type | Description |
---|---|
Object | An object at index position in a Set, or null if the Set contains fewer than (index + 1) elements. |
has
Checks a Set object to determine whether the specified element is present in the collection or not.
Parameters
Name | Type | Description |
---|---|---|
element | Object | The element to locate in the Set. |
Return Value
Type | Description |
---|---|
boolean | If the element is found, returns `true`, otherwise, `false`. |
isEmpty
Checks a Set object to determine whether it is empty.
Return Value
Type | Description |
---|---|
boolean | If the Set is empty, returns `true`, otherwise, `false`. |
isNotEmpty
Checks a Set object to determine whether it is not empty.
Return Value
Type | Description |
---|---|
boolean | If the Set is not empty, returns `true`, otherwise, `false`. |
last
Find the last object in a collection based on the order in which the elements were added to the Set.
Return Value
Type | Description |
---|---|
Object | The last object in a collection or null if collection is empty. |
values
Get an iterator for the entries in a Set. The same as `entries()`.
Return Value
Type | Description |
---|---|
Iterator.<Object> | An iterator for the collection of values. |
See Also
For details, see entries().