Instance properties and methods listed below.
Collections also expose a few more methods for the built-in event system, which is explained in Watcher section.
length
Property returning the length of the collection as an integer.
at(n)
Returns the model at specific index.
push(model)
Pushes the model, and adds it to the end of the collection.
every(iteratorFn)
Tests whether all models in the collection pass the test implemented by the provided function.
filter(iteratorFn)
Creates a new array with all models that pass the test implemented by the provided function.
find(iteratorFn)
Returns a model in the collection, if a model in the array satisfies the provided testing function. Otherwise undefined
is returned.
forEach(iteratorFn)
Executes provided function once per model in the collection.
includes(model)
Determines whether colelction includes a certain model, returning true
or false
as appropriate.
indexOf(model)
Returns the first index at which a given model can be found in the collection, or -1 if it is not present.
map(fn)
Creates a new array with the results of calling the provided function on every model in this collection.
reduce(fn, initialValue)
Applies the function against an accumulator and each model of the collection (from left-to-right) to reduce it to a single value.
some(iteratorFn)
Tests whether some model in the collection passes the test implemented by the provided function.
pop()
Removes the last model from the collection and returns that model. This method changes the length of the collection.
shift()
Removes the first model from the collection and returns that model. This method changes the length of the collection.
unshift(model)
Adds one or more models to the beginning of the collection and returns the new length of the collection.
remove(model)
Removes model from the collection.
removeFrom(n)
Removes model from the given n
index.
difference(models)
Creates an array of unique models not included in the other given models array.
findIndex(model)
This method is like find()
, except that it returns the index of the first model.
first()
Gets the first model of the collection.
last()
Gets the last model of the collection.
nth(n = 0)
Gets the model at n
index of the collection. If n
is negative, the nth element from the end is returned.
take(n = 1)
Creates a slice of array with n
models taken from the beginning.
takeRight(n = 1)
Creates a slice of array with n
models taken from the end.
destroy()
Destroys the collection and its watchers.
toJS()
Converts the collection to an plain array, and also converting the models into plain objects recursively.