Instances of this class will be returned when accessing object properties whose type is "Set"

Sets mostly behave like normal JavaScript Sets, with a few exceptions: They can only store values of a single type (indicated by the type and optional properties of the Set). They can only be modified inside a write transaction. Unlike JavaScript's Set, Realm~Set does NOT make any guarantees about the traversal order of values(), entries(), keys(), or forEach iterations. If values in a Set are required to have some order, it must be implemented by the developer by, for example, wrapping values in an object that holds a user-supplied insertion order.

Type Parameters

  • T = unknown

Hierarchy (view full)

Constructors

Properties

[unscopables]: {
    [iterator]?: boolean;
    [unscopables]?: boolean;
    at?: boolean;
    concat?: boolean;
    copyWithin?: boolean;
    entries?: boolean;
    every?: boolean;
    fill?: boolean;
    filter?: boolean;
    find?: boolean;
    findIndex?: boolean;
    flat?: boolean;
    flatMap?: boolean;
    forEach?: boolean;
    includes?: boolean;
    indexOf?: boolean;
    join?: boolean;
    keys?: boolean;
    lastIndexOf?: boolean;
    length?: boolean;
    map?: boolean;
    pop?: boolean;
    push?: boolean;
    reduce?: boolean;
    reduceRight?: boolean;
    reverse?: boolean;
    shift?: boolean;
    slice?: boolean;
    some?: boolean;
    sort?: boolean;
    splice?: boolean;
    toLocaleString?: boolean;
    toString?: boolean;
    unshift?: boolean;
    values?: boolean;
    [x: number]: boolean | undefined;
}

An Object whose truthy properties are properties that are excluded from the 'with' environment bindings of the associated objects.

Type declaration

  • [x: number]: boolean | undefined
  • Optional [iterator]?: boolean
  • Optional Readonly [unscopables]?: boolean
  • Optional at?: boolean
  • Optional concat?: boolean
  • Optional copyWithin?: boolean
  • Optional entries?: boolean
  • Optional every?: boolean
  • Optional fill?: boolean
  • Optional filter?: boolean
  • Optional find?: boolean
  • Optional findIndex?: boolean
  • Optional flat?: boolean
  • Optional flatMap?: boolean
  • Optional forEach?: boolean
  • Optional includes?: boolean
  • Optional indexOf?: boolean
  • Optional join?: boolean
  • Optional keys?: boolean
  • Optional lastIndexOf?: boolean
  • Optional length?: boolean
  • Optional map?: boolean
  • Optional pop?: boolean
  • Optional push?: boolean
  • Optional reduce?: boolean
  • Optional reduceRight?: boolean
  • Optional reverse?: boolean
  • Optional shift?: boolean
  • Optional slice?: boolean
  • Optional some?: boolean
  • Optional sort?: boolean
  • Optional splice?: boolean
  • Optional toLocaleString?: boolean
  • Optional toString?: boolean
  • Optional unshift?: boolean
  • Optional values?: boolean

Accessors

  • get length(): number
  • Returns number

    The number of values.

  • set length(value): void
  • Parameters

    • value: number

    Returns void

    Throws

    An Error as the length property cannot be assigned.

  • get optional(): boolean
  • Whether null is a valid value for the collection.

    Returns boolean

    Whether null is a valid value for the collection.

  • get size(): number
  • Returns number

    The number of values in the Set.

  • get type(): string
  • Name of the type of items.

    Returns string

    The name of the type of values.

Methods

  • Returns IterableIterator<T>

    An iterator that iterates over all the values in the collection.

  • Add a new value to the Set.

    Parameters

    • value: T

      Value to add to the Set.

    Returns this

    The Set itself, after adding the new value.

    Throws

    A TypeError if a value is not of a type which can be stored in the Set, or if an object being added to the Set does not match the for the Set.

    Throws

    An Error if not inside a write transaction.

  • Add a listener callback which will be called when a live collection instance changes.

    Parameters

    • callback: CollectionChangeCallback<T, [T, T]>

      A function to be called when changes occur.

    • Optional keyPaths: string | string[]

      Indicates a lower bound on the changes relevant for the listener. This is a lower bound, since if multiple listeners are added (each with their own keyPaths) the union of these key-paths will determine the changes that are considered relevant for all listeners registered on the collection. In other words: A listener might fire more than the key-paths specify, if other listeners with different key-paths are present.

    Returns void

    Note

    deletions and oldModifications report the indices in the collection before the change happened, while insertions and newModifications report the indices into the new version of the collection.

    Throws

    A TypeAssertionError if callback is not a function.

    Example

    wines.addListener((collection, changes) => {
    // collection === wines
    console.log(`${changes.insertions.length} insertions`);
    console.log(`${changes.oldModifications.length} oldModifications`);
    console.log(`${changes.newModifications.length} newModifications`);
    console.log(`${changes.deletions.length} deletions`);
    console.log(`new size of collection: ${collection.length}`);
    });

    Example

    wines.addListener((collection, changes) => {
    console.log("A wine's brand might have changed");
    }, ["brand"]);

    Note

    Adding the listener is an asynchronous operation, so the callback is invoked the first time to notify the caller when the listener has been added. Thus, when the callback is invoked the first time it will contain empty arrays for each property in the changes object.

  • Parameters

    • index: number

    Returns undefined | T

    The element at the given index in the array; undefined if there is no element at the given index.

    See

    Array.prototype.at()

    Params

    index - The index of the element to return from the array. If the index is a negative number, the element at array.length + index is returned.

  • Computes the average of the values in the collection or of the given property among all the objects in the collection, or undefined if the collection is empty.

    Only supported for int, float and double properties. null values are ignored entirely by this method and will not be factored into the average.

    Parameters

    • Optional property: string

      For a collection of objects, the property to take the average of.

    Returns undefined | number

    The sum.

    Throws

    An Error if no property with the name exists or if property is not numeric.

  • Remove all values from the Set.

    Returns void

    Throws

    An Error if not inside a write transaction.

  • Parameters

    • Rest ...items: ConcatArray<T>[]

      Arrays and/or values to concatenate into a new array.

    Returns T[]

    A new array with the results of calling a provided function on every element in this array.

  • Parameters

    • Rest ...items: (T | ConcatArray<T>)[]

      Arrays and/or values to concatenate into a new array.

    Returns T[]

    A new array with the results of calling a provided function on every element in this array.

  • Delete a value from the Set.

    Parameters

    • value: T

      Value to delete from the Set.

    Returns boolean

    true if the value existed in the Set prior to deletion, false if not.

    Throws

    An Error if not inside a write transaction.

  • Returns string

    A string describing the filters applied to this collection.

  • Returns Generator<[T, T], any, unknown>

    An iterator over the entries of the Set. Each entry is a two-element array containing the value from the Set, followed by a copy of the same value ([value, value]).

  • Type Parameters

    • S

    Parameters

    • predicate: ((value, index, array) => value is S)
        • (value, index, array): value is S
        • Parameters

          • value: T
          • index: number
          • array: readonly T[]

          Returns value is S

    • Optional thisArg: any

    Returns this is readonly S[]

    true if the callback function returns a truthy value for every collection element; otherwise, false.

    See

    Array.prototype.every()

    Params

    predicate - A function to test for each element.

    Params

    predicate.value - The current element being processed in the collection.

    Params

    predicate.index - The index of the current element being processed in the collection.

    Params

    predicate.array - The collection every was called upon.

    Params

    thisArg - An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

  • Parameters

    • predicate: ((value, index, array) => unknown)
        • (value, index, array): unknown
        • Parameters

          • value: T
          • index: number
          • array: readonly T[]

          Returns unknown

    • Optional thisArg: any

    Returns boolean

    true if the callback function returns a truthy value for every collection element; otherwise, false.

    See

    Array.prototype.every()

    Params

    predicate - A function to test for each element.

    Params

    predicate.value - The current element being processed in the collection.

    Params

    predicate.index - The index of the current element being processed in the collection.

    Params

    predicate.array - The collection every was called upon.

    Params

    thisArg - An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

  • Type Parameters

    • S

    Parameters

    • predicate: ((value, index, array) => value is S)
        • (value, index, array): value is S
        • Parameters

          • value: T
          • index: number
          • array: readonly T[]

          Returns value is S

    • Optional thisArg: any

    Returns S[]

    A new array containing the elements of the collection for which the predicate function returned true.

    See

    Array.prototype.filter()

    Params

    predicate - A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the collection.

    Params

    predicate.value - The current element being processed in the collection.

    Params

    predicate.index - The index of the current element being processed in the collection.

    Params

    predicate.array - The collection filter was called upon.

    Params

    thisArg - An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

  • Parameters

    • predicate: ((value, index, array) => unknown)
        • (value, index, array): unknown
        • Parameters

          • value: T
          • index: number
          • array: readonly T[]

          Returns unknown

    • Optional thisArg: any

    Returns T[]

    A new array containing the elements of the collection for which the predicate function returned true.

    See

    Array.prototype.filter()

    Params

    predicate - A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the collection.

    Params

    predicate.value - The current element being processed in the collection.

    Params

    predicate.index - The index of the current element being processed in the collection.

    Params

    predicate.array - The collection filter was called upon.

    Params

    thisArg - An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

  • Returns new Results that represent this collection being filtered by the provided query.

    Parameters

    • queryString: string

      Query used to filter objects from the collection.

    • Rest ...args: unknown[]

      Each subsequent argument is used by the placeholders (e.g. $0, $1, $2, …) in the query.

    Returns Results<T>

    Results filtered according to the provided query.

    Throws

    An Error if the query or any other argument passed into this method is invalid.

    Note

    This is currently only supported for collections of Realm Objects.

    Example

    let merlots = wines.filtered('variety == "Merlot" && vintage <= $0', maxYear);
    
  • Type Parameters

    • S

    Parameters

    • predicate: ((this, value, index, obj) => value is S)
        • (this, value, index, obj): value is S
        • Parameters

          • this: void
          • value: T
          • index: number
          • obj: T[]

          Returns value is S

    • Optional thisArg: any

    Returns undefined | S

    The value of the first element in the array that satisfies the provided testing function. Otherwise, undefined is returned.

    See

    Array.prototype.find()

    Params

    predicate - A function that accepts up to three arguments. The find method calls the predicate function one time for each element in the collection.

    Params

    predicate.value - The value of the element.

    Params

    predicate.index - The index of the element.

    Params

    predicate.obj - The object being traversed.

    Params

    thisArg - An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

  • Type Parameters

    • T

    Parameters

    • predicate: ((value, index, obj) => unknown)
        • (value, index, obj): unknown
        • Parameters

          • value: T
          • index: number
          • obj: T[]

          Returns unknown

    • Optional thisArg: any

    Returns undefined | T

    The value of the first element in the array that satisfies the provided testing function. Otherwise, undefined is returned.

    See

    Array.prototype.find()

    Params

    predicate - A function that accepts up to three arguments. The find method calls the predicate function one time for each element in the collection.

    Params

    predicate.value - The value of the element.

    Params

    predicate.index - The index of the element.

    Params

    predicate.obj - The object being traversed.

    Params

    thisArg - An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

  • Parameters

    • predicate: ((value, index, obj) => unknown)
        • (value, index, obj): unknown
        • Parameters

          • value: T
          • index: number
          • obj: readonly T[]

          Returns unknown

    • Optional thisArg: any

    Returns number

    The index of the first element in the array that satisfies the provided testing function. Otherwise, -1 is returned.

    See

    Array.prototype.findIndex()

    Params

    predicate - A function that accepts up to three arguments. The findIndex method calls the predicate function one time for each element in the collection.

    Params

    predicate.value - The value of the element.

    Params

    predicate.index - The index of the element.

    Params

    predicate.obj - The object being traversed.

    Params

    thisArg - An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

  • Type Parameters

    • A

    • D extends number = 1

    Parameters

    • this: A
    • Optional depth: D

    Returns FlatArray<A, D>[]

    A new array with the sub-array elements concatenated into it.

    See

    Array.prototype.flat()

    Params

    depth - The depth level specifying how deep a nested array structure should be flattened. Defaults to 1.

  • Type Parameters

    • U

    • This = undefined

    Parameters

    • callback: ((this, value, index, array) => U | readonly U[])
        • (this, value, index, array): U | readonly U[]
        • Parameters

          • this: This
          • value: T
          • index: number
          • array: T[]

          Returns U | readonly U[]

    • Optional thisArg: This

    Returns U[]

    A new array with each element being the result of the callback function and flattened to a depth of 1.

    See

    Array.prototype.flatMap()

    Params

    callback - Function that produces an element of the new Array, taking three arguments:

    Params

    callback.currentValue - The current element being processed in the array.

    Params

    callback.index - The index of the current element being processed in the array.

    Params

    callback.array - The array flatMap was called upon.

    Params

    thisArg - Value to use as this when executing callback.

  • Parameters

    • callbackfn: ((value, index, array) => void)
        • (value, index, array): void
        • Parameters

          • value: T
          • index: number
          • array: readonly T[]

          Returns void

    • Optional thisArg: any

    Returns void

    See

    Array.prototype.forEach()

    Params

    callbackfn - A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the collection.

    Params

    callbackfn.value - The current element being processed in the collection.

    Params

    callbackfn.index - The index of the current element being processed in the collection.

    Params

    callbackfn.array - The collection forEach was called upon.

    Params

    thisArg - An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

  • Check for existence of a value in the Set.

    Parameters

    • value: T

      Value to search for in the Set

    Returns boolean

    true if the value exists in the Set, false if not.

    Throws

    A TypeError if a value is not of a type which can be stored in the Set, or if an object being added to the Set does not match the object schema for the Set.

  • Parameters

    • searchElement: T
    • Optional fromIndex: number

    Returns boolean

    true if the searchElement is found in the array; otherwise, false.

    See

    Array.prototype.includes()

    Params

    searchElement - The element to search for.

    Params

    fromIndex - The position in this array at which to begin searching for searchElement. A negative value searches from the index of array.length + fromIndex by asc.

    Note

    fromIndex is currently not supported. So all searches start at index 0.

  • Parameters

    • searchElement: T
    • Optional fromIndex: number

    Returns number

    The first index at which a given element can be found in the collection, or -1 if it is not present.

    See

    Array.prototype.indexOf()

    Params

    searchElement - Element to locate in the collection.

    Params

    fromIndex - The collection index at which to begin the search. If omitted, the search starts at index 0.

    Note

    fromIndex is currently not supported. So all searches start at index 0.

  • Checks if this collection is empty.

    Returns boolean

    true if the collection is empty, false if not.

  • Checks if this Set has not been deleted and is part of a valid Realm.

    Returns boolean

    true if the set can be safely accessed, false if not.

  • Parameters

    • Optional separator: string

    Returns string

    A string representing the elements of the collection.

    See

    Array.prototype.join()

    Params

    separator - A string used to separate one element of the collection from the next in the resulting String.

  • Returns Generator<number, any, unknown>

    An iterator with all keys in the collection.

  • Parameters

    • searchElement: T
    • Optional fromIndex: number

    Returns number

    The last index at which a given element can be found in the collection, or -1 if it is not present. The collection is searched backwards, starting at fromIndex.

    See

    Array.prototype.lastIndexOf()

    Params

    searchElement - Element to locate in the collection.

    Params

    fromIndex - The collection index at which to begin the search. If omitted, the search starts at the last index.

  • Type Parameters

    • U

    Parameters

    • callbackfn: ((value, index, array) => U)
        • (value, index, array): U
        • Parameters

          • value: T
          • index: number
          • array: readonly T[]

          Returns U

    • Optional thisArg: any

    Returns U[]

    A new array containing the results of calling the callbackfn function on each element in the collection.

    See

    Array.prototype.map()

    Params

    callbackfn - A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the collection.

    Params

    callbackfn.value - The current element being processed in the collection.

    Params

    callbackfn.index - The index of the current element being processed in the collection.

    Params

    callbackfn.array - The collection map was called upon.

    Params

    thisArg - An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

  • Returns the maximum value of the values in the collection or of the given property among all the objects in the collection, or undefined if the collection is empty.

    Only supported for int, float, double and date properties. null values are ignored entirely by this method and will not be returned.

    Parameters

    • Optional property: string

      For a collection of objects, the property to take the maximum of.

    Returns undefined | number | Date

    The maximum value.

    Throws

    An Error if no property with the name exists or if property is not numeric/date.

  • Returns the minimum value of the values in the collection or of the given property among all the objects in the collection, or undefined if the collection is empty.

    Only supported for int, float, double and date properties. null values are ignored entirely by this method and will not be returned.

    Parameters

    • Optional property: string

      For a collection of objects, the property to take the minimum of.

    Returns undefined | number | Date

    The minimum value.

    Throws

    A TypeAssertionError if no property with the name exists or if property is not numeric/date.

  • Parameters

    • callbackfn: ((previousValue, currentValue, currentIndex, array) => T)
        • (previousValue, currentValue, currentIndex, array): T
        • Parameters

          • previousValue: T
          • currentValue: T
          • currentIndex: number
          • array: readonly T[]

          Returns T

    Returns T

    The value that results from the reduction.

    See

    Array.prototype.reduce()

    Params

    callbackfn - A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the collection.

    Params

    callbackfn.previousValue - The value previously returned in the last invocation of the callbackfn function, or initialValue, if supplied. (See below.)

    Params

    callbackfn.currentValue - The current element being processed in the collection.

    Params

    callbackfn.currentIndex - The index of the current element being processed in the collection.

    Params

    callbackfn.array - The collection reduce was called upon.

    Params

    initialValue - If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an element value.

  • Parameters

    • callbackfn: ((previousValue, currentValue, currentIndex, array) => T)
        • (previousValue, currentValue, currentIndex, array): T
        • Parameters

          • previousValue: T
          • currentValue: T
          • currentIndex: number
          • array: readonly T[]

          Returns T

    • initialValue: T

    Returns T

    The value that results from the reduction.

    See

    Array.prototype.reduce()

    Params

    callbackfn - A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the collection.

    Params

    callbackfn.previousValue - The value previously returned in the last invocation of the callbackfn function, or initialValue, if supplied. (See below.)

    Params

    callbackfn.currentValue - The current element being processed in the collection.

    Params

    callbackfn.currentIndex - The index of the current element being processed in the collection.

    Params

    callbackfn.array - The collection reduce was called upon.

    Params

    initialValue - If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an element value.

  • Type Parameters

    • U

    Parameters

    • callbackfn: ((previousValue, currentValue, currentIndex, array) => U)
        • (previousValue, currentValue, currentIndex, array): U
        • Parameters

          • previousValue: U
          • currentValue: T
          • currentIndex: number
          • array: readonly T[]

          Returns U

    • initialValue: U

    Returns U

    The value that results from the reduction.

    See

    Array.prototype.reduce()

    Params

    callbackfn - A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the collection.

    Params

    callbackfn.previousValue - The value previously returned in the last invocation of the callbackfn function, or initialValue, if supplied. (See below.)

    Params

    callbackfn.currentValue - The current element being processed in the collection.

    Params

    callbackfn.currentIndex - The index of the current element being processed in the collection.

    Params

    callbackfn.array - The collection reduce was called upon.

    Params

    initialValue - If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an element value.

  • Parameters

    • callbackfn: ((previousValue, currentValue, currentIndex, array) => T)
        • (previousValue, currentValue, currentIndex, array): T
        • Parameters

          • previousValue: T
          • currentValue: T
          • currentIndex: number
          • array: readonly T[]

          Returns T

    Returns T

    The value that results from the reduction.

    See

    Array.prototype.reduceRight()

    Params

    callbackfn - A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the collection.

    Params

    callbackfn.previousValue - The value previously returned in the last invocation of the callbackfn function, or initialValue, if supplied. (See below.)

    Params

    callbackfn.currentValue - The current element being processed in the collection.

    Params

    callbackfn.currentIndex - The index of the current element being processed in the collection.

    Params

    callbackfn.array - The collection reduceRight was called upon.

    Params

    initialValue - If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an element value.

  • Parameters

    • callbackfn: ((previousValue, currentValue, currentIndex, array) => T)
        • (previousValue, currentValue, currentIndex, array): T
        • Parameters

          • previousValue: T
          • currentValue: T
          • currentIndex: number
          • array: readonly T[]

          Returns T

    • initialValue: T

    Returns T

    The value that results from the reduction.

    See

    Array.prototype.reduceRight()

    Params

    callbackfn - A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the collection.

    Params

    callbackfn.previousValue - The value previously returned in the last invocation of the callbackfn function, or initialValue, if supplied. (See below.)

    Params

    callbackfn.currentValue - The current element being processed in the collection.

    Params

    callbackfn.currentIndex - The index of the current element being processed in the collection.

    Params

    callbackfn.array - The collection reduceRight was called upon.

    Params

    initialValue - If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an element value.

  • Type Parameters

    • U

    Parameters

    • callbackfn: ((previousValue, currentValue, currentIndex, array) => U)
        • (previousValue, currentValue, currentIndex, array): U
        • Parameters

          • previousValue: U
          • currentValue: T
          • currentIndex: number
          • array: readonly T[]

          Returns U

    • initialValue: U

    Returns U

    The value that results from the reduction.

    See

    Array.prototype.reduceRight()

    Params

    callbackfn - A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the collection.

    Params

    callbackfn.previousValue - The value previously returned in the last invocation of the callbackfn function, or initialValue, if supplied. (See below.)

    Params

    callbackfn.currentValue - The current element being processed in the collection.

    Params

    callbackfn.currentIndex - The index of the current element being processed in the collection.

    Params

    callbackfn.array - The collection reduceRight was called upon.

    Params

    initialValue - If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an element value.

  • Remove all callback listeners from the collection instance.

    Returns void

  • Parameters

    • Optional start: number
    • Optional end: number

    Returns T[]

    A new array containing the elements between the start and end indices.

    See

    Array.prototype.slice()

    Params

    start - Zero-based index at which to begin extraction.

    Params

    end - Zero-based index at which to end extraction. It extracts up to but not including end.

  • Create a frozen snapshot of the collection.

    Values added to and removed from the original collection will not be reflected in the Results returned by this method, including if the values of properties are changed to make them match or not match any filters applied.

    This is not a deep snapshot. Realm objects contained in this snapshot will continue to update as changes are made to them, and if they are deleted from the Realm they will be replaced by null at the respective indices.

    Returns Results<T>

    Results which will not live update.

  • Parameters

    • predicate: ((value, index, array) => unknown)
        • (value, index, array): unknown
        • Parameters

          • value: T
          • index: number
          • array: readonly T[]

          Returns unknown

    • Optional thisArg: any

    Returns boolean

    true if the callback function returns a truthy value for any collection element; otherwise, false.

    See

    Array.prototype.some()

    Params

    predicate - A function to test for each element.

    Params

    predicate.value - The current element being processed in the collection.

    Params

    predicate.index - The index of the current element being processed in the collection.

    Params

    predicate.array - The collection every was called upon.

    Params

    thisArg - An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

  • Returns new Results that represent a sorted view of this collection.

    A collection of Realm Objects can be sorted on one or more properties of those objects, or of properties of objects linked to by those objects. To sort by a single property, simply pass the name of that property to sorted(), optionally followed by a boolean indicating if the sort should be reversed. For more than one property, you must pass an array of sort descriptors which list which properties to sort on.

    Collections of other types sort on the values themselves rather than properties of the values, and so no property name or sort descriptors should be supplied.

    Parameters

    • Optional reverse: boolean

      Sort in descending order rather than ascended. It may not be applied if descriptor is an array of sort descriptors.

    Returns Results<T>

    Results sorted according to the arguments passed in.

    Throws

    An Error if a specified property does not exist.

  • Returns new Results that represent a sorted view of this collection.

    A collection of Realm Objects can be sorted on one or more properties of those objects, or of properties of objects linked to by those objects. To sort by a single property, simply pass the name of that property to sorted(), optionally followed by a boolean indicating if the sort should be reversed. For more than one property, you must pass an array of sort descriptors which list which properties to sort on.

    Collections of other types sort on the values themselves rather than properties of the values, and so no property name or sort descriptors should be supplied.

    Parameters

    • descriptor: SortDescriptor[]

      The property name(s) to sort the collection on.

    Returns Results<T>

    Results sorted according to the arguments passed in.

    Throws

    An Error if a specified property does not exist.

  • Returns new Results that represent a sorted view of this collection.

    A collection of Realm Objects can be sorted on one or more properties of those objects, or of properties of objects linked to by those objects. To sort by a single property, simply pass the name of that property to sorted(), optionally followed by a boolean indicating if the sort should be reversed. For more than one property, you must pass an array of sort descriptors which list which properties to sort on.

    Collections of other types sort on the values themselves rather than properties of the values, and so no property name or sort descriptors should be supplied.

    Parameters

    • descriptor: string

      The property name(s) to sort the collection on.

    • Optional reverse: boolean

    Returns Results<T>

    Results sorted according to the arguments passed in.

    Throws

    An Error if a specified property does not exist.

  • Computes the sum of the values in the collection or of the given property among all the objects in the collection, or 0 if the collection is empty.

    Only supported for int, float and double properties. null values are ignored entirely by this method.

    Parameters

    • Optional property: string

      For a collection of objects, the property to take the sum of.

    Returns number

    The sum.

    Throws

    An Error if no property with the name exists or if property is not numeric.

  • The plain object representation for JSON serialization. Use circular JSON serialization libraries such as @ungap/structured-clone and flatted to stringify Realm entities that have circular structures.

    Returns DefaultObject[]

    An array of plain objects.

Generated using TypeDoc