Realm.List

Instances of this class will be returned when accessing object properties whose type is "list" (see ObjectSchemaProperty). The objects contained in a list are accessible through its index properties and may only be modified inside a write transaction.

length
readonly

The number of objects in the list.

Type:
number
filtered(query, arg)Realm.Results

Returns new results that represent this list being filtered by the provided query.

let merlots = wines.filtered('varietal == "Merlot" && vintage <= $0', maxYear);
Parameters:
  • query
    • Type: string
    • Query used to filter results.

  • arg optional repeatable
    • Type: any
    • Each subsequent argument is used by the placeholders (e.g. $0, $1, $2, …) in the query.

Throws:
  • Error
    • If the query or any other argument passed into this method is invalid.

Returns: Realm.Results filtered according to the provided query.
pop()Realm.Object or undefined

Remove the last object from the list and return it.

Throws:
  • Error
    • If not inside a write transaction.

Returns: Realm.Object or undefined if the list is empty.
push(object)number

Add one or more objects to the end of the list.

Parameters:
  • object repeatable
    • Type: Realm.Object
    • Each object’s type must match objectType specified in the schema.

Throws:
  • TypeError
    • If an object is of the wrong type.

  • Error
    • If not inside a write transaction.

Returns: number equal to the new length of the list after adding objects.
shift()Realm.Object or undefined

Remove the first object from the list and return it.

Throws:
  • Error
    • If not inside a write transaction.

Returns: Realm.Object or undefined if the list is empty.
snapshot()Realm.Results

Create a frozen snapshot of the list. This means changes to the list will not be reflected in the results returned by this method. However, deleted objects will become null at their respective indices.

Returns: Realm.Results which will not live update.
sorted(descriptor, reverse)Realm.Results

Returns new results that represent this list being sorted by the provided property (or properties) of each object.

Parameters:
  • descriptor
    • Type: string or [SortDescriptor, ...]
    • The property name(s) to sort results by.

  • reverse optional
    • Type: boolean
    • Default: false
    • May only be provided if descriptor is a string.

Throws:
  • Error
    • If a specified property does not exist.

Returns: Realm.Results sorted according to the arguments passed in
unshift(object)number

Add one or more objects to the beginning of the list.

Parameters:
  • object repeatable
    • Type: Realm.Object
    • Each object’s type must match objectType specified in the schema.

Throws:
  • TypeError
    • If an object is of the wrong type.

  • Error
    • If not inside a write transaction.

Returns: number equal to the new length of the list after adding objects.