Extends
Members
The number of objects in the collection.
Type:
number
Inherited Methods
- callback
- Type:
function
Function to execute on each object in the collection. If this function returns
true
for every object, then this method will returntrue
. This function takes three arguments:object
– The current object being processed in the collection.index
– The index of the object being processed in the collection.collection
– The collection itself.
- thisArg optional
- Type:
object
The value of
this
whencallback
is called.- query
- Type:
string
Query used to filter objects from the collection.
- arg optional repeatable
- Type:
any
Each subsequent argument is used by the placeholders (e.g.
$0
,$1
,$2
, …) in the query.-
Error
If the query or any other argument passed into this method is invalid.
- callback
- Type:
function
Function to execute on each object in the collection. If this function returns
true
, then that object will be returned by this method. This function takes three arguments:object
– The current object being processed in the collection.index
– The index of the object being processed in the collection.collection
– The collection itself.
- thisArg optional
- Type:
object
The value of
this
whencallback
is called.- callback
- Type:
function
Function to execute on each object in the collection. If this function returns
true
, then the index of that object will be returned by this method. This function takes three arguments:object
– The current object being processed in the collection.index
– The index of the object being processed in the collection.collection
– The collection itself.
- thisArg optional
- Type:
object
The value of
this
whencallback
is called.- callback
- Type:
function
Function to execute on each object in the collection. This function takes three arguments:
object
– The current object being processed in the collection.index
– The index of the object being processed in the collection.collection
– The collection itself.
- thisArg optional
- Type:
object
The value of
this
whencallback
is called.- separator optional
- Type:
string
- Default:
","
A string to separate the return values of the
toString()
method being called on each object in the collection.- callback
- Type:
function
Function to execute on each object in the collection. This function takes three arguments:
object
– The current object being processed in the collection.index
– The index of the object being processed in the collection.collection
– The collection itself.
- thisArg optional
- Type:
object
The value of
this
whencallback
is called.- callback
- Type:
function
Function to execute on each object in the collection. This function takes four arguments:
previousValue
– The value previously returned in the last invocation of the callback, orinitialValue
, if supplied.object
– The current object being processed in the collection.index
– The index of the object being processed in the collection.collection
– The collection itself.
- initialValue optional
- Type:
object
The value to use as the first argument to the first call of the
callback
.-
TypeError
If the collection is empty and no
initialValue
was supplied.
- If collection consists of a single object, and no
initalValue
was supplied, then that object will be returned. - If the collection is empty, then
initialValue
must be supplied and will be returned. - callback
- Type:
function
Function to execute on each object, from right to left, in the collection. This function takes four arguments:
previousValue
– The value previously returned in the last invocation of the callback, orinitialValue
, if supplied.object
– The current object being processed in the collection.index
– The index of the object being processed in the collection.collection
– The collection itself.
- initialValue optional
- Type:
object
The value to use as the first argument to the first call of the
callback
.-
TypeError
If the collection is empty and no
initialValue
was supplied.
- If collection consists of a single object, and no
initalValue
was supplied, then that object will be returned. - If the collection is empty, then
initialValue
must be supplied and will be returned. - start optional
- Type:
number
- Default:
0
The start index. If negative, then the start index will be counted from the end of the collection.
- end optional
- Type:
number
The end index. The objects up to, but not including, the end index will be include in the return value. If negative, then the end index will be counted from the end of the collection. If omitted, then all objects from the start index will be included in the return value.
- callback
- Type:
function
Function to execute on each object in the collection. If this function ever returns
true
, then this method will returntrue
. This function takes three arguments:object
– The current object being processed in the collection.index
– The index of the object being processed in the collection.collection
– The collection itself.
- thisArg optional
- Type:
object
The value of
this
whencallback
is called.- descriptor
- Type:
string
or[SortDescriptor, ...]
The property name(s) to sort the objects in the collection.
- reverse optional
- Type:
boolean
- Default:
false
May only be provided if
descriptor
is a string.-
Error
If a specified property does not exist.
boolean
Parameters:
boolean
representing if callback
returned true
for every object in the
collection.
Realm.Results
Returns new Results that represent this collection being filtered by the provided query.
Parameters:
Throws:
Realm.Results
filtered according to the provided query.
Example:
let merlots = wines.filtered('variety == "Merlot" && vintage <= $0', maxYear);
Realm.Object
or undefined
Parameters:
Realm.Object
or undefined
if the callback
did not return true
for any object
in the collection.
number
Parameters:
number
representing the index where the callback
returned true
, or -1
if true
was never returned.
Parameters:
boolean
Checks if this collection has not been deleted and is part of a valid Realm.
Returns:boolean
indicating if the collection can be safely accessed.
string
Joins all objects in the collection into a string.
Parameters:
string
Iterator
Iterator
of each index in the collection
[any, ...]
Parameters:
[any, ...]
– the return values of callback
after being called on every object
in the collection.
any
Parameters:
Throws:
any
– the value returned by the final invocation of callback
, except for
the following special cases:
any
Parameters:
Throws:
any
– the value returned by the final invocation of callback
, except for
the following special cases:
[Realm.Object, ...]
Parameters:
[Realm.Object, ...]
containing the objects from the start index up to, but not
including, the end index.
Realm.Results
Create a frozen snapshot of the collection. This means objects added to and removed from the
original collection will not be reflected in the Results returned by this method.
However, objects deleted from the Realm will become null
at their respective indices.
This is not a deep snapshot, meaning the objects contained in this snapshot will
continue to update as changes are made to them.
Realm.Results
which will not live update.
boolean
Parameters:
boolean
– true
when callback
returns true
for an object in the collection,
otherwise false
.
Realm.Results
Returns new Results that represent this collection being sorted by the provided property (or properties) of each object.
Parameters:
Throws:
Realm.Results
sorted according to the arguments passed in
Iterator
This is the same method as the values()
method.
Its presence makes collections iterable, thus able to be used with ES6
for-of
loops,
...
spread operators, and more.
Iterator
of each Realm object in the collection
Example:
for (let object of collection) {
// do something with each object
}