Constructor
new List(values, optionsopt)
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
values |
Array | Map | Object | Elements of the List. For Maps or objects, the values (in order of iteration) are used as the List elements. If no argument is supplied, it defaults to an empty Array. |
||||||||||||
options |
Object |
<optional> |
{}
|
Further options. Properties
|
Classes
Methods
delete(i, optionsopt) → {List}
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
i |
string | number | Index or name of the List element to delete.
Numbers are passed to |
||||||||||||
options |
Object |
<optional> |
{}
|
Further options. Properties
|
Returns:
The List after deleting the i
-th element.
If inPlace = true
, this is a reference to the current instance, otherwise a new instance is created and returned.
- Type
- List
deleteByIndex(i, optionsopt) → {List}
Parameters:
Name | Type | Attributes | Default | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
i |
number | Index of the List element to delete.
This should be non-negative and no less than |
|||||||||||||||||
options |
Object |
<optional> |
{}
|
Further options. Properties
|
Returns:
The List after deleting the i
-th element.
If inPlace = true
, this is a reference to the current instance, otherwise a new instance is created and returned.
- Type
- List
deleteByName(name) → {List}
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name |
string | Name of the List element to delete.
This should already exist in |
||
options.name |
string |
<optional> <nullable> |
null
|
See the argument of the same name in |
options.inPlace |
boolean |
<optional> |
false
|
Whether to modify this List instance in place.
If |
Returns:
The List after deleting the name
d element.
If inPlace = true
, this is a reference to the current instance, otherwise a new instance is created and returned.
- Type
- List
get(i)
Parameters:
Name | Type | Description |
---|---|---|
i |
string | number | Index or name of the List element to retrieve.
Numbers are passed to |
Returns:
The List element at/for i
.
getByIndex(i)
Parameters:
Name | Type | Description |
---|---|---|
i |
number | Index of the List element to retrieve.
This should be non-negative and less than |
Returns:
The i
-th List element.
getByName(name)
Parameters:
Name | Type | Description |
---|---|---|
name |
string | Name of the List element to retrieve.
This should be present in |
Returns:
The List element corresponding to name
.
If duplicates of name
are present in the list, the first occurrence is returned.
has(name) → {boolean}
Parameters:
Name | Type | Description |
---|---|---|
name |
string | Name of a List element. |
Returns:
Whether the name exists in this List.
- Type
- boolean
length() → {number}
Returns:
Length of the list.
- Type
- number
names() → (nullable) {Array}
Returns:
Array of names of the List elements, or null
if the List is unnamed.
- Type
- Array
nameToIndex(name) → {number}
Parameters:
Name | Type | Description |
---|---|---|
name |
string | Name of a List element. |
Returns:
Index of the name in names
.
If duplicate names are present, the first occurrence is returned.
If the name is not present, -1 is returned.
- Type
- number
set(i, x, optionsopt) → {List}
Parameters:
Name | Type | Attributes | Default | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
i |
string | number | Index or name of the list element to set.
Numbers are passed to |
|||||||||||||||||
x |
* | Value of a List element. |
|||||||||||||||||
options |
Object |
<optional> |
{}
|
Further options. Properties
|
Returns:
The List after setting the i
-th element to x
.
If inPlace = true
, this is a reference to the current instance, otherwise a new instance is created and returned.
- Type
- List
setByIndex(i, x, optionsopt) → {List}
Parameters:
Name | Type | Attributes | Default | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
i |
number | Index of the List element to set.
This should be non-negative and no greater than |
|||||||||||||||||
x |
* | Value of a List element. |
|||||||||||||||||
options |
Object |
<optional> |
{}
|
Further options. Properties
|
Returns:
The List after setting the i
-th element to x
.
If inPlace = true
, this is a reference to the current instance, otherwise a new instance is created and returned.
- Type
- List
setByName(name, x, optionsopt) → {List}
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
name |
string | Name of the List element to set.
If this already exists in |
||||||||||||
x |
* | Value of a List element. |
||||||||||||
options |
Object |
<optional> |
{}
|
Further options. Properties
|
Returns:
The List after setting the name
d entry to x
.
If inPlace = true
, this is a reference to the current instance, otherwise a new instance is created and returned.
- Type
- List
setNames(namesnullable, optionsopt) → {List}
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
names |
Array |
<nullable> |
Array of strings of length equal to |
|||||||||||
options |
Object |
<optional> |
{}
|
Further options. Properties
|
Returns:
The List after replacing the names with names
.
If inPlace = true
, this is a reference to the current instance, otherwise a new instance is created and returned.
- Type
- List
sliceIndices(indices, optionsopt) → {List}
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
indices |
Array | Array of numbers or strings specifying the List elements to retain in the slice. Numbers are interpreted as positional indices while strings are interpreted as names. |
||||||||||||
options |
Object |
<optional> |
{}
|
Further options. Properties
|
Returns:
A List containing the specified elements in indices
.
If inPlace = true
, this is a reference to the current instance, otherwise a new instance is created and returned.
- Type
- List
sliceRange(start, end, optionsopt) → {List}
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
start |
number | Index of the first element in the slice. |
||||||||||||
end |
number | Index past the last element in the slice. |
||||||||||||
options |
Object |
<optional> |
{}
|
Further options. Properties
|
Returns:
A List that is sliced to [start, end)
.
If inPlace = true
, this is a reference to the current instance, otherwise a new instance is created and returned.
- Type
- List
toArray() → {Array}
Returns:
Array of values, equivalent to values
.
- Type
- Array
toMap() → {Map}
Returns:
Map of name-value pairs. If duplicate names are present, only the value for the first occurrence is reported. If the List is unnamed, an error is thrown.
- Type
- Map
toObject() → {Object}
Returns:
Object of name-value pairs. If duplicate names are present, only the value for the first occurrence is reported. If the List is unnamed, an error is thrown.
- Type
- Object
values() → {Array}
Returns:
Array containing the List elements.
- Type
- Array