napi_create_array_with_length


napi_status napi_create_array_with_length(napi_env env,
                                          size_t length,
                                          napi_value* result) 
  • [in] env:调用 API 的环境。

    ¥[in] env: The environment that the API is invoked under.

  • [in] lengthArray 的初始长度。

    ¥[in] length: The initial length of the Array.

  • [out] result:代表 JavaScript Arraynapi_value

    ¥[out] result: A napi_value representing a JavaScript Array.

如果 API 成功,则返回 napi_ok

¥Returns napi_ok if the API succeeded.

此 API 返回对应于 JavaScript Array 类型的 Node-API 值。Array 的长度属性设置为传入的长度参数。但是,不保证底层缓冲区在创建数组时由 VM 预先分配。该行为留给底层 VM 实现。如果缓冲区必须是可以通过 C 直接读取和/或写入的连续内存块,请考虑使用 napi_create_external_arraybuffer

¥This API returns a Node-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 数组在 ECMAScript 语言规范的 第 22.1 节 中进行了描述。

¥JavaScript arrays are described in Section 22.1 of the ECMAScript Language Specification.