Readonly
[unscopables]An Object whose truthy properties are properties that are excluded from the 'with' environment bindings of the associated objects.
Optional
Readonly
[unscopables]?: booleanIs an object whose properties have the value 'true' when they will be absent when used in a 'with' statement.
Optional
length?: booleanGets or sets the length of the array. This is a number one higher than the highest index in the array.
The number of values in the list.
An Error as the length property cannot be assigned.
Whether null
is a valid value for the collection.
Whether null
is a valid value for the collection.
Name of the type of items.
The name of the type of values.
An iterator that iterates over all the values in the collection.
Add a listener callback
which will be called when a live collection instance changes.
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.
deletions and
oldModificationsreport the indices in the collection before the change happened, while
insertionsand
newModificationsreport the indices into the new version of the collection. @throws A {@link 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.
The element at the given index in the array; undefined
if there is no element at the given index.
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.
Optional
property: stringFor a collection of objects, the property to take the average of.
The sum.
An Error if no property with the name exists or if property is not numeric.
Rest
...items: ConcatArray<T>[]Arrays and/or values to concatenate into a new array.
A new array with the results of calling a provided function on every element in this array.
Rest
...items: (T | ConcatArray<T>)[]Arrays and/or values to concatenate into a new array.
A new array with the results of calling a provided function on every element in this array.
true
if the callback function returns a truthy value for every collection element; otherwise, false
.
predicate - A function to test for each element.
predicate.value - The current element being processed in the collection.
predicate.index - The index of the current element being processed in the collection.
predicate.array - The collection every
was called upon.
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.
Optional
thisArg: anytrue
if the callback function returns a truthy value for every collection element; otherwise, false
.
predicate - A function to test for each element.
predicate.value - The current element being processed in the collection.
predicate.index - The index of the current element being processed in the collection.
predicate.array - The collection every
was called upon.
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.
A new array containing the elements of the collection for which the predicate
function returned true
.
predicate - A function that accepts up to three arguments. The filter
method calls the predicate
function one time for each element in the collection.
predicate.value - The current element being processed in the collection.
predicate.index - The index of the current element being processed in the collection.
predicate.array - The collection filter
was called upon.
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.
Optional
thisArg: anyA new array containing the elements of the collection for which the predicate
function returned true
.
predicate - A function that accepts up to three arguments. The filter
method calls the predicate
function one time for each element in the collection.
predicate.value - The current element being processed in the collection.
predicate.index - The index of the current element being processed in the collection.
predicate.array - The collection filter
was called upon.
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.
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.
Results filtered according to the provided query.
An Error if the query or any other argument passed into this method is invalid.
This is currently only supported for collections of Realm Objects.
let merlots = wines.filtered('variety == "Merlot" && vintage <= $0', maxYear);
The value of the first element in the array that satisfies the provided testing function. Otherwise, undefined
is returned.
predicate - A function that accepts up to three arguments. The find
method calls the predicate
function one time for each element in the collection.
predicate.value - The value of the element.
predicate.index - The index of the element.
predicate.obj - The object being traversed.
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.
Optional
thisArg: anyThe value of the first element in the array that satisfies the provided testing function. Otherwise, undefined
is returned.
predicate - A function that accepts up to three arguments. The find
method calls the predicate
function one time for each element in the collection.
predicate.value - The value of the element.
predicate.index - The index of the element.
predicate.obj - The object being traversed.
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.
Optional
thisArg: anyThe index of the first element in the array that satisfies the provided testing function. Otherwise, -1 is returned.
predicate - A function that accepts up to three arguments. The findIndex
method calls the predicate
function one time for each element in the collection.
predicate.value - The value of the element.
predicate.index - The index of the element.
predicate.obj - The object being traversed.
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.
A new array with each element being the result of the callback function and flattened to a depth of 1.
callback - Function that produces an element of the new Array, taking three arguments:
callback.currentValue - The current element being processed in the array.
callback.index - The index of the current element being processed in the array.
callback.array - The array flatMap
was called upon.
thisArg - Value to use as this when executing callback.
Optional
thisArg: anycallbackfn - A function that accepts up to three arguments. forEach
calls the callbackfn function one time for each element in the collection.
callbackfn.value - The current element being processed in the collection.
callbackfn.index - The index of the current element being processed in the collection.
callbackfn.array - The collection forEach
was called upon.
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.
Optional
fromIndex: numbertrue
if the searchElement
is found in the array; otherwise, false
.
searchElement - The element to search for.
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.
fromIndex
is currently not supported. So all searches start at index 0.
Optional
fromIndex: numberThe first index at which a given element can be found in the collection, or -1 if it is not present.
searchElement - Element to locate in the collection.
fromIndex - The collection index at which to begin the search. If omitted, the search starts at index 0.
fromIndex
is currently not supported. So all searches start at index 0.
Optional
fromIndex: numberThe 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
.
searchElement - Element to locate in the collection.
fromIndex - The collection index at which to begin the search. If omitted, the search starts at the last index.
A new array containing the results of calling the callbackfn
function on each element in the collection.
callbackfn - A function that accepts up to three arguments. The map
method calls the callbackfn
function one time for each element in the collection.
callbackfn.value - The current element being processed in the collection.
callbackfn.index - The index of the current element being processed in the collection.
callbackfn.array - The collection map
was called upon.
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.
Optional
property: stringFor a collection of objects, the property to take the maximum of.
The maximum value.
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.
Optional
property: stringFor a collection of objects, the property to take the minimum of.
The minimum value.
A TypeAssertionError if no property with the name exists or if property is not numeric/date.
Moves one element of the list from one index to another.
The index of the element to move.
The destination index of the element.
An AssertionError if not inside a write transaction or if any of the input indexes is less than 0 or greater than or equal to the size of the list.
Remove the last value from the list and return it.
The last value or undefined if the list is empty.
an AssertionError If not inside a write transaction.
Add one or more values to the end of the list.
Rest
...items: T[]Values to add to the list.
The new length of the list after adding the values.
A {TypeError} if a value is not of a type which can be stored in the list, or if an object being added to the list does not match the ObjectSchema for the list.
An AssertionError if not inside a write transaction.
The value that results from the reduction.
callbackfn - A function that accepts up to four arguments. The reduce
method calls the callbackfn
function one time for each element in the collection.
callbackfn.previousValue - The value previously returned in the last invocation of the callbackfn
function, or initialValue
, if supplied. (See below.)
callbackfn.currentValue - The current element being processed in the collection.
callbackfn.currentIndex - The index of the current element being processed in the collection.
callbackfn.array - The collection reduce
was called upon.
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.
The value that results from the reduction.
callbackfn - A function that accepts up to four arguments. The reduce
method calls the callbackfn
function one time for each element in the collection.
callbackfn.previousValue - The value previously returned in the last invocation of the callbackfn
function, or initialValue
, if supplied. (See below.)
callbackfn.currentValue - The current element being processed in the collection.
callbackfn.currentIndex - The index of the current element being processed in the collection.
callbackfn.array - The collection reduce
was called upon.
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.
The value that results from the reduction.
callbackfn - A function that accepts up to four arguments. The reduce
method calls the callbackfn
function one time for each element in the collection.
callbackfn.previousValue - The value previously returned in the last invocation of the callbackfn
function, or initialValue
, if supplied. (See below.)
callbackfn.currentValue - The current element being processed in the collection.
callbackfn.currentIndex - The index of the current element being processed in the collection.
callbackfn.array - The collection reduce
was called upon.
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.
The value that results from the reduction.
callbackfn - A function that accepts up to four arguments. The reduceRight
method calls the callbackfn
function one time for each element in the collection.
callbackfn.previousValue - The value previously returned in the last invocation of the callbackfn
function, or initialValue
, if supplied. (See below.)
callbackfn.currentValue - The current element being processed in the collection.
callbackfn.currentIndex - The index of the current element being processed in the collection.
callbackfn.array - The collection reduceRight
was called upon.
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.
The value that results from the reduction.
callbackfn - A function that accepts up to four arguments. The reduceRight
method calls the callbackfn
function one time for each element in the collection.
callbackfn.previousValue - The value previously returned in the last invocation of the callbackfn
function, or initialValue
, if supplied. (See below.)
callbackfn.currentValue - The current element being processed in the collection.
callbackfn.currentIndex - The index of the current element being processed in the collection.
callbackfn.array - The collection reduceRight
was called upon.
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.
The value that results from the reduction.
callbackfn - A function that accepts up to four arguments. The reduceRight
method calls the callbackfn
function one time for each element in the collection.
callbackfn.previousValue - The value previously returned in the last invocation of the callbackfn
function, or initialValue
, if supplied. (See below.)
callbackfn.currentValue - The current element being processed in the collection.
callbackfn.currentIndex - The index of the current element being processed in the collection.
callbackfn.array - The collection reduceRight
was called upon.
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.
Removes the element of the list at the specified index.
The index of the element to remove.
An AssertionError if not inside a write transaction or the input index is less than 0 or greater than or equal to the size of the list.
Remove the listener callback
from the collection instance.
Callback function that was previously added as a listener through the Collection.addListener method.
a TypeAssertionError If callback
is not a function.
Remove the first value from the list and return it.
The first value or undefined
if the list is empty.
An AssertionError if not inside a write transaction.
Optional
start: numberOptional
end: numberA new array containing the elements between the start and end indices.
start - Zero-based index at which to begin extraction.
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.
Results which will not live update.
Optional
thisArg: anytrue
if the callback function returns a truthy value for any collection element; otherwise, false
.
predicate - A function to test for each element.
predicate.value - The current element being processed in the collection.
predicate.index - The index of the current element being processed in the collection.
predicate.array - The collection every
was called upon.
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.
Optional
reverse: booleanSort in descending order rather than ascended.
It may not be applied if descriptor
is an array of sort descriptors.
Results sorted according to the arguments passed in.
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.
The property name(s) to sort the collection on.
Results sorted according to the arguments passed in.
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.
The property name(s) to sort the collection on.
Optional
reverse: booleanResults sorted according to the arguments passed in.
An Error if a specified property does not exist.
Changes the contents of the list by removing value and/or inserting new value.
The start index. If greater than the length of the list,
the start index will be set to the length instead. If negative, then the start index
will be counted from the end of the list (e.g. list.length - index
).
Optional
deleteCount: numberThe number of values to remove from the list. If not provided, then all values from the start index through the end of the list will be removed.
An array containing the value that were removed from the list. The array is empty if no value were removed.
Changes the contents of the list by removing value and/or inserting new value.
The start index. If greater than the length of the list,
the start index will be set to the length instead. If negative, then the start index
will be counted from the end of the list (e.g. list.length - index
).
The number of values to remove from the list. If not provided, then all values from the start index through the end of the list will be removed.
Rest
...items: T[]Values to insert into the list starting at index
.
An array containing the value that were removed from the list. The array is empty if no value were removed.
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.
Optional
property: stringFor a collection of objects, the property to take the sum of.
The sum.
An Error if no property with the name exists or if property is not numeric.
Swaps the positions of the elements of the list at two indexes.
The index of the first element.
The index of the second element.
An AssertionError if not inside a write transaction or if any of the input indexes is less than 0 or greater than or equal to the size of the list.
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.
An array of plain objects.
Add one or more values to the beginning of the list.
Rest
...items: T[]Values to add to the list.
The new length of the list after adding the values.
A {TypeError} if a value is not of a type which can be stored in the list, or if an object being added to the list does not match the ObjectSchema for the list.
An AssertionError if not inside a write transaction.
An iterator with all values in the collection.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values | Array.prototype.values()}
Generated using TypeDoc
Instances of this class will be returned when accessing object properties whose type is
"list"
.Lists mostly behave like normal Javascript Arrays, except for that they can only store values of a single type (indicated by the
type
andoptional
properties of the List), and can only be modified inside a write transaction.