push

  • function
can.List.prototype.push  

Add elements to the end of a list.

list.push(...elements)

push adds elements onto the end of a List.

Parameters

  1. elements {*}

    the elements to add to the List

Returns

{Number}

the new length of the List

push adds elements onto the end of a List here is an example:

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

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

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

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

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

Events

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

See also

push has a counterpart in pop, or you may be looking for unshift and its counterpart shift.