Class JsArray<T extends JavaScriptObject>

java.lang.Object
com.google.gwt.core.client.JavaScriptObject
com.google.gwt.core.client.JsArray<T>
Type Parameters:
T - the concrete type of object contained in this array

public class JsArray<T extends JavaScriptObject> extends JavaScriptObject
A simple wrapper around a homogeneous native array of JavaScriptObject values. This class may not be directly instantiated, and can only be returned from a native method. For example, native JsArray getNativeArray() /*-{ return [ { x: 0, y: 1}, { x: 2, y: 3}, { x: 4, y: 5}, ]; }-* /;
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
  • Method Summary

    Modifier and Type
    Method
    Description
    final T
    get(int index)
    Gets the object at a given index.
    final String
    Convert each element of the array to a String and join them with a comma separator.
    final String
    join(String separator)
    Convert each element of the array to a String and join them with a comma separator.
    final int
    Gets the length of the array.
    final void
    push(T value)
    Pushes the given value onto the end of the array.
    final void
    set(int index, T value)
    Sets the object value at a given index.
    final void
    setLength(int newLength)
    Reset the length of the array.
    final T
    Shifts the first value off the array.
    final void
    unshift(T value)
    Shifts a value onto the beginning of the array.

    Methods inherited from class com.google.gwt.core.client.JavaScriptObject

    cast, createArray, createArray, createFunction, createObject, equals, hashCode, toSource, toString

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • JsArray

      protected JsArray()
  • Method Details

    • get

      public final T get(int index)
      Gets the object at a given index.
      Parameters:
      index - the index to be retrieved
      Returns:
      the object at the given index, or null if none exists
    • join

      public final String join()
      Convert each element of the array to a String and join them with a comma separator. The value returned from this method may vary between browsers based on how JavaScript values are converted into strings.
    • join

      public final String join(String separator)
      Convert each element of the array to a String and join them with a comma separator. The value returned from this method may vary between browsers based on how JavaScript values are converted into strings.
    • length

      public final int length()
      Gets the length of the array.
      Returns:
      the array length
    • push

      public final void push(T value)
      Pushes the given value onto the end of the array.
    • set

      public final void set(int index, T value)
      Sets the object value at a given index. If the index is out of bounds, the value will still be set. The array's length will be updated to encompass the bounds implied by the added object.
      Parameters:
      index - the index to be set
      value - the object to be stored
    • setLength

      public final void setLength(int newLength)
      Reset the length of the array.
      Parameters:
      newLength - the new length of the array
    • shift

      public final T shift()
      Shifts the first value off the array.
      Returns:
      the shifted value
    • unshift

      public final void unshift(T value)
      Shifts a value onto the beginning of the array.
      Parameters:
      value - the value to the stored