PUBLIC
Uses: Ember.Array
Uses: Ember.MutableEnumerable
Defined in: packages/ember-runtime/lib/mixins/mutable_array.js:40
Module: ember-runtime
This mixin defines the API for modifying array-like objects. These methods can be applied only to a collection that keeps its items in an ordered set. It builds upon the Array mixin and adds methods to modify the array. One concrete implementations of this class include ArrayProxy.
It is important to use the methods in this class to modify arrays so that changes are observable. This allows the binding system in Ember to function correctly.
Note that an Array can change even if it does not implement this mixin. For example, one might implement a SparseArray that cannot be directly modified, but if its underlying enumerable changes, it will change also.
Ember.Arraypublic
Push the object onto the end of the array if it is not already present in the array.
let cities = ['Chicago', 'Berlin'];
cities.addObject('Lima'); // ['Chicago', 'Berlin', 'Lima']
cities.addObject('Berlin'); // ['Chicago', 'Berlin', 'Lima']
*
Ember.Array Ember.Arraypublic
Remove all elements from the array. This is useful if you want to reuse an existing array without having to recreate it.
let colors = ['red', 'green', 'blue']; colors.length; // 3 colors.clear(); // [] colors.length; // 0
Ember.Array Booleanpublic
Returns true if the passed object can be found in the array. This method is a Polyfill for ES 2016 Array.includes. If no startAt argument is given, the starting location to search is 0. If it's negative, searches from the index of this.length + startAt by asc.
[1, 2, 3].includes(2); // true [1, 2, 3].includes(4); // false [1, 2, 3].includes(3, 2); // true [1, 2, 3].includes(3, 3); // false [1, 2, 3].includes(3, -1); // true [1, 2, 3].includes(1, -1); // false [1, 2, 3].includes(1, -4); // true [1, 2, NaN].includes(NaN); // true
Object
Number
Boolean Ember.Arraypublic
This will use the primitive replace() method to insert an object at the specified index.
let colors = ['red', 'green', 'blue']; colors.insertAt(2, 'yellow'); // ['red', 'green', 'yellow', 'blue'] colors.insertAt(5, 'orange'); // Error: Index out of range
Number
Object
Ember.Array Pop object from array or nil if none are left. Works just like pop() but it is KVO-compliant.
let colors = ['red', 'green', 'blue']; colors.popObject(); // 'blue' console.log(colors); // ['red', 'green']
Push the object onto the end of the array. Works just like push() but it is KVO-compliant.
let colors = ['red', 'green'];
colors.pushObject('black'); // ['red', 'green', 'black']
colors.pushObject(['yellow']); // ['red', 'green', ['yellow']]
*
Ember.Arraypublic
Add the objects in the passed numerable to the end of the array. Defers notifying observers of the change until all objects are added.
let colors = ['red']; colors.pushObjects(['yellow', 'orange']); // ['red', 'yellow', 'orange']
Ember.Enumerable
Ember.Array Ember.Arraypublic
Remove an object at the specified index using the replace() primitive method. You can pass either a single index, or a start and a length.
If you pass a start and length that is beyond the length this method will throw an OUT_OF_RANGE_EXCEPTION.
let colors = ['red', 'green', 'blue', 'yellow', 'orange']; colors.removeAt(0); // ['green', 'blue', 'yellow', 'orange'] colors.removeAt(2, 2); // ['green', 'blue'] colors.removeAt(4, 2); // Error: Index out of range
Number
Number
Ember.Array Ember.Arraypublic
Remove all occurrences of an object in the array.
let cities = ['Chicago', 'Berlin', 'Lima', 'Chicago'];
cities.removeObject('Chicago'); // ['Berlin', 'Lima']
cities.removeObject('Lima'); // ['Berlin']
cities.removeObject('Tokyo') // ['Berlin']
*
Ember.Array Required. You must implement this method to apply this mixin.
This is one of the primitives you must implement to support Ember.Array. You should replace amt objects started at idx with the objects in the passed array. You should also call this.enumerableContentDidChange()
Number
Number
Array
Ember.Arraypublic
Reverse objects in the array. Works just like reverse() but it is KVO-compliant.
Ember.Array Ember.Arraypublic
Replace all the receiver's content with content of the argument. If argument is an empty array receiver will be cleared.
let colors = ['red', 'green', 'blue']; colors.setObjects(['black', 'white']); // ['black', 'white'] colors.setObjects([]); // []
Ember.Array
Ember.Array Shift an object from start of array or nil if none are left. Works just like shift() but it is KVO-compliant.
let colors = ['red', 'green', 'blue']; colors.shiftObject(); // 'red' console.log(colors); // ['green', 'blue']
Unshift an object to start of array. Works just like unshift() but it is KVO-compliant.
let colors = ['red'];
colors.unshiftObject('yellow'); // ['yellow', 'red']
colors.unshiftObject(['black']); // [['black'], 'yellow', 'red']
*
Ember.Arraypublic
Adds the named objects to the beginning of the array. Defers notifying observers until all objects have been added.
let colors = ['red'];
colors.unshiftObjects(['black', 'white']); // ['black', 'white', 'red']
colors.unshiftObjects('yellow'); // Type Error: 'undefined' is not a function
Ember.Enumerable
Ember.Array This is the handler for the special array content property. If you get this property, it will return this. If you set this property to a new array, it will replace the current content.
This property overrides the default property defined in Ember.Enumerable.
© 2017 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
http://emberjs.com/api/classes/Ember.MutableArray.html