Skip to content

Array Operations ​

The Array Operations block changes a list that you keep in a variable. You can add an item at the start or end, remove the first or last item, or keep only the items that match a rule.

When to use it ​

  • Build up a list, like adding each result inside a For Each Loop.
  • Keep a queue: add to the end (push) and take from the front (shift).
  • Keep only the items you need, like users who are active.
  • Don't use it to change the items themselves. Use Transformer for that.
  • Don't use it to loop over a list. Use For Each Loop.

Inputs ​

FieldRequiredDefaultWhat it does
OperationYesnoneWhat to do, see the table below.
DatasourceYesnoneThe name of the variable that holds the list. It must already exist, for example saved with Set Variable.
ValueFor push and unshiftnoneThe item to add. A plain value, an object, or a JS expression like js: input.id.
Use Param As InputNooffOn: add the previous block's output as the item, instead of Value.
Filter ConditionsFor filternoneRules that an item must pass to be kept. Built like If Condition rules, and each item is available as input.
OperationWhat it does
pushAdds the item to the end of the list.
unshiftAdds the item to the beginning.
popRemoves the last item.
shiftRemoves the first item.
filterKeeps only the items that pass the Filter Conditions.

Outputs ​

HandleWhen it is used
Next (right)Always. The next block receives the whole updated list.

Also, the Save output to variable option can store the updated list in outputs.<name>.

Example ​

Keep only the active users in a variable called users, which holds:

json
[{ "name": "Avery", "active": true }, { "name": "Kai", "active": false }]
FieldValue
Operationfilter
Datasourceusers
Filter ConditionsOne rule with operator JS: return input.active;

The variable users is now [{ "name": "Avery", "active": true }], and the next block receives that same list.

How it behaves ​

  • The variable is changed in place. The list in the Datasource is updated, not just the output.
  • Pop and shift return the list, not the removed item. To use the removed item, read it with JS Runner before you remove it.
  • The Datasource must be a list. If the variable is missing or is not a list, the block fails with datasource is not an array and the Error Handler runs.
  • Pop or shift on an empty list does nothing.
  • No filter rules keeps everything. An empty condition list passes every item.
  • Filter keeps the order of the items it keeps.

Released under the Apache License 2.0. Enterprise features are under the Fluxify Enterprise Edition License.