unshift
Add items to the beginning of a DefineList.
list.unshift(...items)
unshift
adds items onto the beginning of a DefineList.
import {DefineList} from "can";
const list = new DefineList(['Alice']);
list.unshift('Bob', 'Eve');
console.log(list.get()); //-> ['Bob', 'Eve', 'Alice']
Parameters
- items
{*}
:The items 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 beginning
of the DefineList, you can use apply
:
import {DefineList} from "can";
const names = ['Bob', 'Eve'];
const list = new DefineList(['Alice']);
list.unshift.apply(list, names);
console.log(list.get()); //-> ['Bob', 'Eve', 'Alice']
Events
unshift
causes add and length events to be fired.
See also
unshift
has a counterpart in shift, or you may be
looking for push and its counterpart pop.