.sortBy(key,direction)

Description

The sortBy method takes in an array or objects as input and returns the array but sorted by a key in its items.

Parameters

Key is the key that you want to sort the objects inside the array

Direction can either be empty, "ascending" or "descending"

Usage On Arrays

arr = [
  {"num":2},
  {"num":1},
  {"num":3},
]
// setup the array

log arr.sortBy("num","ascending")
// [{"num":1},{"num":2},{"num":3}]
// returns the array but sorted

Last updated