sort array by multiple fields
This block is part of the array group and was last modified in core v10.4.28.
sort array by multiple fields v10.4.28 Sorts the elements of an array by multiple fields in priority order and returns a new, sorted array. The input array is not changed. `fields` and `sort` are two separate, parallel arrays of plain text values that line up by position: fields = ["category", "price"] with sort = ["asc", "desc"] sorts by category ascending and then by price descending.
- Array required
arrayThe array of objects to sort. It is not modified; a new sorted array is returned on the output pin.
- fields required
arrayA flat array of field names to sort by, in priority order : for example ["category", "price"]. Dot paths into nested objects are supported ("address.city"). Items that are tied on the first field are compared on the second, and so on. This pin holds field names only; the direction for each field is given separately on the `sort` pin.
- sort required
arrayA flat array of directions, matched to `fields` BY POSITION: sort[0] is the direction for fields[0], sort[1] for fields[1], and so on. Each entry is the text "asc" or "desc" (case-insensitive); a missing entry defaults to "asc" and any other value is treated as descending. This is NOT an array of objects : do not pass [{field: …, sort: …}]. Example: fields = ["category", "price"] with sort = ["asc", "desc"] sorts by category A→Z and, within each category, by price high→low.
- Array
arrayThe output array.
Sorts object items by multiple dot-path fields in priority order: fields lists the paths and sort gives asc or desc per position (case-insensitive, missing entries default to asc); items tied on one field fall through to the next. Comparison follows JS rules: numbers numeric, strings lexicographic, null smallest. Outputs a NEW sorted array; the input array's order is NOT changed.
A typical wiring for sort array by multiple fields: the array out pin feeds length.
Version history
Introduced in v10.4.28.
Back to
array Return to the main group to view all sub-groups Back to array Return to the group to view all blocks within this group 