napi_status napi_create_array_with_length(napi_env env,
size_t length,
napi_value* result)
[in] env
: The environment that the API is invoked under.[in] length
: The initial length of theArray
.[out] result
: Anapi_value
representing a JavaScriptArray
.
Returns napi_ok
if the API succeeded.
This API returns an N-API value corresponding to a JavaScript Array
type.
The Array
‘s length property is set to the passed-in length parameter.
However, the underlying buffer is not guaranteed to be pre-allocated by the VM
when the array is created. That behavior is left to the underlying VM
implementation. If the buffer must be a contiguous block of memory that can be
directly read and/or written via C, consider using
[napi_create_external_arraybuffer
][].
JavaScript arrays are described in [Section 22.1][] of the ECMAScript Language Specification.