Class JsArray<T>
java.lang.Object
com.vaadin.client.flow.collection.JsArray<T>
- Type Parameters:
T- the type of the array items
- Direct Known Subclasses:
JreJsArray
Native JS Array interface with an alternative implementation for JRE usage.
Use
JsCollections.array() to create an appropriate instance.- Since:
- 1.0
- Author:
- Vaadin Ltd
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclear()Clears the array.voidforEach(JsCollections.ForEachCallback<T> callback) Invokes the provided callback for each value in this array.final Tget(int index) Gets the item at the given index.final booleanisEmpty()Checks if the array is empty (length == 0).intlength()Gets the current length of this array.intAdds items to the end of this array.final intAdds items to the end of this array.final Tremove(int index) Removes the item at the given index.final booleanRemoves the given item from the array.final voidSets the item at the given index.shift()Removes and returns the first value from the array.Removes and adds a number of items at the given index.spliceArray(int index, int remove, JsArray<? extends T> add) Removes and adds a number of items at the given index.
-
Constructor Details
-
JsArray
protected JsArray()Should not be directly created.
-
-
Method Details
-
get
Gets the item at the given index. This is corresponding toreturn array[index]in JavaScript.- Parameters:
index- the index to get- Returns:
- the item at the given index
-
set
Sets the item at the given index. This is corresponding toarray[index] = valuein JavaScript.- Parameters:
index- the index to setvalue- the value to set
-
push
Adds items to the end of this array.- Parameters:
values- the new values to add- Returns:
- the new length of the array
-
pushArray
Adds items to the end of this array.- Parameters:
values- the new values to add- Returns:
- the new length of the array
-
length
@JsProperty(name="length") public int length()Gets the current length of this array.- Returns:
- the array length
-
spliceArray
Removes and adds a number of items at the given index.- Parameters:
index- the index at which do do the operationremove- the number of items to removeadd- new items to add- Returns:
- an array of removed items
-
splice
Removes and adds a number of items at the given index.- Parameters:
index- the index at which do do the operationremove- the number of items to removeadd- new items to add- Returns:
- an array of removed items
-
remove
Removes the item at the given index.- Parameters:
index- the index to remove- Returns:
- the remove item
-
clear
Clears the array.- Returns:
- the cleared array
-
isEmpty
@JsOverlay public final boolean isEmpty()Checks if the array is empty (length == 0).- Returns:
- true if the array is empty, false otherwise
-
remove
Removes the given item from the array.- Parameters:
toRemove- the item to remove- Returns:
trueif the item was found and removed from the array,falseotherwise
-
shift
Removes and returns the first value from the array.- Returns:
- the first value of the array or null if the array is empty
-
forEach
Invokes the provided callback for each value in this array.- Parameters:
callback- the callback to invoke for each value
-