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
将当前的JavaScript对象转换为JSArray类型。 JSArray type.
|
JSValue |
get(int index)
Returns JavaScript value at the given
返回JavaScript数组中给定索引处的JavaScript值。 index in the JavaScript array.
|
boolean |
isArray()
Indicates whether JavaScript value is an array.
指示JavaScript值是否为数组。 |
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
在JavaScript数组中的给定索引处更新/插入JavaScript值。 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.
-元素在数组中的位置。必须> 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.
-元素在数组中的位置。必须>0。可以大于数组大小。
value
- a new value associated with the property with the given
index
. Cannot be
null
or
JSObject
with a different JavaScript context.
-与具有给定的属性相关联的新值。不能为或具有其他JavaScript上下文。
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.