push
Add elements to the end of a list.
list.push(...elements)
push
adds elements onto the end of a DefineList.
import { DefineList } from "can";
const names = new DefineList(['Alice']);
names.push('Bob', 'Eve');
console.log(names.get()); //-> ['Alice','Bob', 'Eve']
Parameters
- elements
{*}
:the elements to add to the DefineList
Returns
{Number}
:
the new length of the DefineList
Use
If you have an array you want to concatenate to the end
of the DefineList, you can use apply
:
import {DefineList} from "can";
const names = ['Bob', 'Eve'];
const list = new DefineList(['Alice']);
list.push.apply(list, names);
console.log(list.get()); // ['Alice', 'Bob', 'Eve']
Events
push
causes 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.