get
Gets an item or all items from a DefineList.
list.get()
Returns the list converted into a plain JS array. Any items that also have a
get
method will have their get
method called and the resulting value will be used as item value.
This can be used to recursively convert a list instance to an Array of other plain JavaScript objects. Cycles are supported and only create one object.
get()
can still return other non-plain JS objects like Dates.
Use serialize when a form proper for JSON.stringify
is needed.
import { DefineList } from "can";
const list = new DefineList(["A","B"]);
console.log(list.get()); //-> ["A","B"]
Returns
{Array}
:
A plain JavaScript Array
that contains each item in the list.
list.get(index)
Gets the item at index
. list.get(index)
should be used instead of
list[index]
if the list's items are going to be updated via list.set(index, value)
(as opposed to splice which is the better way).
import {DefineList} from "can";
const list = new DefineList(["A","B"]);
console.log(list.get(1)); //-> "B"
Parameters
- index
{Number}
:A numeric position in the list.
Returns
{*}
:
The value at index.
list.get(prop)
Gets the property at prop
if it might not have already been defined.
import {DefineList} from "can";
const list = new DefineList(["A","B"]);
list.set("count",1000);
console.log(list.get("count")); //-> 1000
Parameters
- prop
{String}
:A property on the list.
Returns
{*}
:
The value at prop
.