Search code examples
gwtgwt2

How can I remove element from JsArray<T>?


I need to remove element from com.google.gwt.core.client.JsArray. Also I need to empty the JsArray.


Solution

  • Answered here: How to delete value from jsarray in GWT?

    Arrays in JavaScript are sparse, so you cannot, for example, remove an object from it and have all the following be moved up to lower indices (like you'd have in Java with a List for instance); at least not with some remove method.

    Using only GWT Java, you can set the value at a specific index to null, but that's it.

    Using JSNI, you can delete it (almost equivalent to setting it to undefined: delete myObjects1) or you can remove it: public static native remove(JsArray arr, int index, int count) /-{
    arr.splice(index, count); }-
    /;