@JsType(isNative=true, namespace="<global>", name="Array") public class JsArray<T> extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
JsArray.CompareFunction |
Constructor and Description |
---|
JsArray() |
Modifier and Type | Method and Description |
---|---|
JsArray<T> |
fill(T value)
Fills all the elements of an array from a start index to an end index with a static value.
|
JsArray<T> |
fill(T value,
int start)
Fills all the elements of an array from a start index to an end index with a static value.
|
JsArray<T> |
fill(T value,
int start,
int end)
Fills all the elements of an array from a start index to an end index with a static value.
|
int |
indexOf(T searchElement)
Returns the first index at which a given element can be found in the array, or -1 if it is not present.
|
int |
indexOf(T searchElement,
int fromElement)
Returns the first index at which a given element can be found in the array, or -1 if it is not present.
|
String |
join(String separator)
Joins all elements of an array into a string.
|
int |
lastIndexOf(T searchElement,
int fromIndex)
last index at which a given element can be found in the array, or -1 if it is not present.
|
int |
length()
Reflects the number of elements in an array.
|
T |
pop()
Removes the last element from an array and returns that element.
|
int |
push(T... elementN)
Adds one or more elements to the end of an array and returns the new length of the array.
|
JsArray<T> |
sort()
Sorts the elements of an array in place and returns the array.
|
JsArray<T> |
sort(JsArray.CompareFunction compareFunction)
Sorts the elements of an array in place and returns the array.
|
String |
toString()
String representing the specified array and its elements.
|
@JsProperty(name="length") public int length()
@JsMethod public JsArray<T> fill(T value)
value
- Value to fill an array.@JsMethod public JsArray<T> fill(T value, int start)
value
- Value to fill an array.start
- Start index, defaults to 0.@JsMethod public JsArray<T> fill(T value, int start, int end)
value
- Value to fill an array.start
- Start index, defaults to 0.end
- End index, defaults to this.length.@JsMethod public T pop()
@JsMethod public int push(T... elementN)
elementN
- The elements to add to the end of the array.length()
property of the object upon which the method was called.@JsMethod public JsArray<T> sort()
@JsMethod public JsArray<T> sort(JsArray.CompareFunction compareFunction)
compareFunction
- Specifies a function that defines the sort order. If omitted, the array is sorted
according to each character's Unicode code point value, according to the string
conversion of each element.@JsMethod public int indexOf(T searchElement)
searchElement
- Element to locate in the array.@JsMethod public int indexOf(T searchElement, int fromElement)
searchElement
- Element to locate in the array.fromElement
- The index to start the search at. If the index is greater than or equal to the array's length,
-1 is returned, which means the array will not be searched. If the provided index value is a
negative number, it is taken as the offset from the end of the array. Note:
if the provided index is negative, the array is still searched from front to back.
If the calculated index is less than 0, then the whole array will be searched.
Default: 0 (entire array is searched).@JsMethod public String join(String separator)
separator
- Specifies a string to separate each element of the array. The separator is converted to a string
if necessary. If omitted, the array elements are separated with a comma. If separator is an
empty string, all elements are joined without any characters in between them. Defaults to ",".@JsMethod public int lastIndexOf(T searchElement, int fromIndex)
searchElement
- Element to locate in the array.fromIndex
- The index at which to start searching backwards. Defaults to the array's
length minus one (arr.length - 1), i.e. the whole array will be searched.
If the index is greater than or equal to the length of the array, the whole array
will be searched. If negative, it is taken as the offset from the end of the array.
Note that even when the index is negative, the array is still searched from back to front.
If the calculated index is less than 0, -1 is returned, i.e. the array will not be searched.Copyright © 2019. All rights reserved.