public class JSArray extends JSObject
JSArray
that references already disposed JavaScript array will cause the IllegalStateException
error. To find out whether JavaScript array is still valid use the getContext().isDisposed()
method.Modifier and Type | Method and Description |
---|---|
JSArray |
asArray()
Casts the current JavaScript object to
JSArray type. |
JSValue |
get(int index)
Returns JavaScript value at the given
index in the JavaScript array. |
boolean |
isArray()
Indicates whether JavaScript value is an array.
|
int |
length()
Returns the number of elements in the array.
|
boolean |
set(int index,
java.lang.Object value)
Updates/inserts JavaScript value at the given
index in the JavaScript array. |
java.lang.String |
toString() |
asJavaObject, asObject, getContext, getOwnPropertyNames, getProperty, getPropertyNames, hasProperty, isJavaObject, isObject, removeProperty, setProperty, setProperty, toJSONString
asBoolean, asBooleanObject, asFunction, asNumber, asNumberObject, asString, asStringObject, getBooleanValue, getNumberValue, getStringValue, isBoolean, isBooleanObject, isFunction, isNull, isNumber, isNumberObject, isString, isStringObject, isUndefined
public int length()
java.lang.IllegalStateException
- when array is already disposed or invalid.public JSValue get(int index)
index
in the JavaScript array.
The index
mustn't be negative. Returns "undefined" JavaScript value
when the index
is out of array bounds (e.g. more than the array size).index
- element position in the array. Must be > 0.java.lang.IllegalStateException
- when array is already disposed or invalid.java.lang.IllegalArgumentException
- when index
is negative.public boolean set(int index, java.lang.Object value)
index
in the JavaScript array.
The index
mustn't be negative. If the index
is more than the array size,
then array size will be extended, the give value
will be inserted at the
specified position, the values between the latest item in the array and the new
index
will be filled with JavaScript "undefined" values (e.g. the undefined
"holes" will be created in the array).index
- element position in the array. Must be > 0. Can be more than array size.value
- a new value associated with the property with the given index
. Cannot be
null
or JSObject
with a different JavaScript context.true
when the given value
was successfully inserted at the given
index
, otherwise returns false
.java.lang.IllegalArgumentException
- when value
is null or represents JSObject
with a different JavaScript context.java.lang.IllegalStateException
- when array is already disposed or invalid.java.lang.IllegalArgumentException
- when index
is negative.public boolean isArray()
JSValue
true
, then
the value can be casted to JSArray
type. For example:
if (value.isArray()) { JSArray array = value.asArray(); }
public JSArray asArray()
JSValue
JSArray
type. If the current object
doesn't represent an array, the IllegalStateException
error is thrown.