set
Sets an item or property or items or properties on a list.
list.set(index, value)
Sets the item at index. Typically, splice should be used instead.
import {DefineList} from "can";
const list = new DefineList(["A","B"]);
list.set(2,"C");
console.log(list[2]); //-> "C"
Splice should be used because it will trigger a length
event. If you are using .set(index, value), you should make sure to use .get(index)
when reading values from the array. If you use .splice(), you can use list[index]
to read values from the array.
Parameters
- index
{Number}:A numeric position in the list.
- value
{*}:The value to add to the list.
list.set(prop, value)
Sets the property at prop. This should be used when the property
isn't already defined.
import {DefineList} from "can";
const list = new DefineList(["A","B"]);
list.set("count",1000);
console.log(list.get("count")); //-> 1000
Parameters
- prop
{Number}:A property name.
- value:
The value to add to the list.
list.set(newProps)
Updates the properties on the list with newProps.
import {DefineList} from "can";
const list = new DefineList(["A","B"]);
list.set({count: 1000, skip: 2});
console.log(list.get("count")); //-> 1000
Parameters
- newProps
{Object}:An object of properties and values to set on the list.