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
@JsType(isNative=true, name="Array", namespace="<global>") public class JsArray<T> extends ObjectNative JS Array interface with an alternative implementation for JRE usage. UseJsCollections.array()to create an appropriate instance.- Since:
- 1.0
- Author:
- Vaadin Ltd
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedJsArray()Should not be directly created.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JsArray<T>clear()Clears the array.voidforEach(JsCollections.ForEachCallback<T> callback)Invokes the provided callback for each value in this array.Tget(int index)Gets the item at the given index.booleanisEmpty()Checks if the array is empty (length == 0).intlength()Gets the current length of this array.intpush(T... values)Adds items to the end of this array.intpushArray(JsArray<? extends T> values)Adds items to the end of this array.Tremove(int index)Removes the item at the given index.booleanremove(T toRemove)Removes the given item from the array.voidset(int index, T value)Sets the item at the given index.Tshift()Removes and returns the first value from the array.JsArray<T>splice(int index, int remove, T... add)Removes and adds a number of items at the given index.JsArray<T>spliceArray(int index, int remove, JsArray<? extends T> add)Removes and adds a number of items at the given index.
-
-
-
Method Detail
-
get
@JsOverlay public final T get(int index)
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
@JsOverlay public final void set(int index, T value)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
public int push(T... values)
Adds items to the end of this array.- Parameters:
values- the new values to add- Returns:
- the new length of the array
-
pushArray
@JsOverlay public final int pushArray(JsArray<? extends T> values)
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
@JsOverlay public final JsArray<T> spliceArray(int index, int remove, JsArray<? extends T> add)
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
public JsArray<T> splice(int index, int remove, T... add)
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
@JsOverlay public final T remove(int index)
Removes the item at the given index.- Parameters:
index- the index to remove- Returns:
- the remove item
-
isEmpty
@JsOverlay public final boolean isEmpty()
Checks if the array is empty (length == 0).- Returns:
- true if the array is empty, false otherwise
-
remove
@JsOverlay public final boolean remove(T toRemove)
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
public T 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
public void forEach(JsCollections.ForEachCallback<T> callback)
Invokes the provided callback for each value in this array.- Parameters:
callback- the callback to invoke for each value
-
-