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 Object
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
    Modifier
    Constructor
    Description
    protected
    Should not be directly created.
  • Method Summary

    Modifier and Type
    Method
    Description
    final JsArray<T>
    Clears the array.
    void
    Invokes the provided callback for each value in this array.
    final T
    get(int index)
    Gets the item at the given index.
    final boolean
    Checks if the array is empty (length == 0).
    int
    Gets the current length of this array.
    int
    push(T... values)
    Adds items to the end of this array.
    final int
    pushArray(JsArray<? extends T> values)
    Adds items to the end of this array.
    final T
    remove(int index)
    Removes the item at the given index.
    final boolean
    remove(T toRemove)
    Removes the given item from the array.
    final void
    set(int index, T value)
    Sets the item at the given index.
    Removes and returns the first value from the array.
    splice(int index, int remove, T... add)
    Removes and adds a number of items at the given index.
    final JsArray<T>
    spliceArray(int index, int remove, JsArray<? extends T> add)
    Removes and adds a number of items at the given index.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JsArray

      protected JsArray()
      Should not be directly created.
  • Method Details

    • get

      @JsOverlay public final T get(int index)
      Gets the item at the given index. This is corresponding to return 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 to array[index] = value in JavaScript.
      Parameters:
      index - the index to set
      value - 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 operation
      remove - the number of items to remove
      add - 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 operation
      remove - the number of items to remove
      add - 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
    • clear

      @JsOverlay public final JsArray<T> 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

      @JsOverlay public final boolean remove(T toRemove)
      Removes the given item from the array.
      Parameters:
      toRemove - the item to remove
      Returns:
      true if the item was found and removed from the array, false otherwise
    • 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