• function

unshift can.Observe.List.prototype.unshift

 

Add elements to the beginning of a List.

list.unshift(...elements)

unshift adds elements onto the beginning of a List.

Parameters

  1. elements {*}

    the elements to add to the List

Returns

{Number}

the new length of the List

unshift adds elements to the front of the list in bulk in the order specified:

var list = new can.Observe.List(['Alice']);

list.unshift('Bob', 'Eve');
list.attr(); // ['Bob', 'Eve', 'Alice']

If you have an array you want to concatenate to the beginning of the List, you can use apply:

var names = ['Bob', 'Eve'],
    list = new can.Observe.List(['Alice']);

list.push.apply(list, names);
list.attr(); // ['Bob', 'Eve', 'Alice']

Events

unshift causes change, add, and length events to be fired.

See also

unshift has a counterpart in [can.Observe.List.shift shift], or you may be looking for [can.Observe.List.push push] and its counterpart [can.Observe.List.pop pop].