Array Value Methods
Array fields should be assigned with arrays. Normalize unknown input before using array methods.
Assignment
const tagValues = Array.isArray(payload.input.tags) ? payload.input.tags : [];
await context.form.update({
recordId: 'record-id',
data: {
tags: tagValues,
},
});
Accepted input examples:
| Input | Normalized Value |
|---|---|
['urgent', 'vip'] | ['urgent', 'vip'] |
'urgent,vip' | split before writing |
null | [] or null, depending on whether the field should be cleared |
Common Methods
| Method | Use |
|---|---|
filter(callback) | Get all items that match a condition |
find(callback) | Get the first item that matches a condition |
map(callback) | Convert every item |
some(callback) | Check whether at least one item matches |
every(callback) | Check whether all items match |
includes(value) | Check whether an array contains a scalar value |
reduce(callback, initial) | Aggregate values |
filter(callback)
Get all items that match a condition.
const items = Array.isArray(payload.input.items) ? payload.input.items : [];
const validItems = items.filter(
(item): item is { sku: string; quantity: number } =>
Boolean(item) &&
typeof item === 'object' &&
!Array.isArray(item) &&
typeof (item as { sku?: unknown }).sku === 'string' &&
Number.isFinite(Number((item as { quantity?: unknown }).quantity))
);
find(callback)
Get the first item that matches a condition.
const firstLargeItem = validItems.find((item) => item.quantity > 10);
map(callback)
Convert every item.
const skuList = validItems.map((item) => item.sku);
some(callback)
Check whether at least one item matches.
const hasLargeItem = validItems.some((item) => item.quantity > 10);
every(callback)
Check whether all items match.
const allHaveSku = validItems.every((item) => item.sku.trim().length > 0);
includes(value)
Check whether an array contains a scalar value.
const tags = Array.isArray(record.data.tags)
? record.data.tags.map((item) => String(item))
: [];
const isVip = tags.includes('vip');
reduce(callback, initial)
Aggregate array values.
const totalQuantity = validItems.reduce((sum, item) => sum + item.quantity, 0);
Find Matching Values
const reviewerIds = Array.isArray(record.data.reviewers)
? record.data.reviewers.map((item) => String(item)).filter(Boolean)
: [];
const targetReviewerIds = reviewerIds.filter((memberId) =>
memberId.startsWith('member-')
);