Dasel
v3
v3
  • Getting started
    • Introduction
    • Installation
    • Concepts
      • Expressions
      • Branches
  • Syntax
    • Whitespace
    • Types/Literals
    • String concatenation
    • Arrays/slices
    • Objects/maps
    • Conditionals
    • Spread
    • Coalesce
  • Input/Output
    • Read/Write formats
    • Stdin
    • Stdout
    • Variables
    • Read/Writer flags
  • Functions
    • add
    • min
    • max
    • reverse
    • toString
    • toInt
    • toFloat
    • typeOf
    • map
    • filter
    • sortBy
    • parse
    • base64e
    • base64d
Powered by GitBook
On this page
  • Examples
  • Simple array
  • Sort by nested property
  1. Functions

sortBy

Sorts the input array by the given expression, either ascending or descending.

Defaults to ascending.

Examples

Simple array

[1, 3, 5, 2, 4].sortBy() // [1, 2, 3, 4, 5]
[1, 3, 5, 2, 4].sortBy($this) // [1, 2, 3, 4, 5]
[1, 3, 5, 2, 4].sortBy($this, asc) // [1, 2, 3, 4, 5]
[1, 3, 5, 2, 4].sortBy($this, desc) // [5, 4, 3, 2, 1]

Sort by nested property

[
    {"x": 1},
    {"x": 3},
    {"x": 5},
    {"x": 2},
    {"x": 4}
].sortBy(x)

// Results in
[
    {"x": 1},
    {"x": 2},
    {"x": 3},
    {"x": 4},
    {"x": 5}
]

PreviousfilterNextparse

Last updated 7 months ago