1# Array 2 3Class [`Napi::Array`][] inherits from class [`Napi::Object`][]. 4 5Arrays are native representations of JavaScript Arrays. `Napi::Array` is a wrapper 6around `napi_value` representing a JavaScript Array. 7 8[`Napi::TypedArray`][] and [`Napi::ArrayBuffer`][] correspond to JavaScript data 9types such as [`Napi::Int32Array`][] and [`Napi::ArrayBuffer`][], respectively, 10that can be used for transferring large amounts of data from JavaScript to the 11native side. An example illustrating the use of a JavaScript-provided 12`ArrayBuffer` in native code is available [here](/tree/main/src/2-js-to-native-conversion/array_buffer_to_native/node-addon-api). 13 14## Constructor 15```cpp 16Napi::Array::Array(); 17``` 18 19Returns an empty array. 20 21If an error occurs, a `Napi::Error` will be thrown. If C++ exceptions are not 22being used, callers should check the result of `Env::IsExceptionPending` before 23attempting to use the returned value. 24 25```cpp 26Napi::Array::Array(napi_env env, napi_value value); 27``` 28- `[in] env` - The environment in which to create the array. 29- `[in] value` - The primitive to wrap. 30 31Returns a `Napi::Array` wrapping a `napi_value`. 32 33If an error occurs, a `Napi::Error` will get thrown. If C++ exceptions are not 34being used, callers should check the result of `Env::IsExceptionPending` before 35attempting to use the returned value. 36 37## Methods 38 39### New 40```cpp 41static Napi::Array Napi::Array::New(napi_env env); 42``` 43- `[in] env` - The environment in which to create the array. 44 45Returns a new `Napi::Array`. 46 47If an error occurs, a `Napi::Error` will get thrown. If C++ exceptions are not 48being used, callers should check the result of `Env::IsExceptionPending` before 49attempting to use the returned value. 50 51### New 52 53```cpp 54static Napi::Array Napi::Array::New(napi_env env, size_t length); 55``` 56- `[in] env` - The environment in which to create the array. 57- `[in] length` - The length of the array. 58 59Returns a new `Napi::Array` with the given length. 60 61If an error occurs, a `Napi::Error` will get thrown. If C++ exceptions are not 62being used, callers should check the result of `Env::IsExceptionPending` before 63attempting to use the returned value. 64 65### Length 66```cpp 67uint32_t Napi::Array::Length() const; 68``` 69 70Returns the length of the array. 71 72Note: 73This can execute JavaScript code implicitly according to JavaScript semantics. 74If an error occurs, a `Napi::Error` will get thrown. If C++ exceptions are not 75being used, callers should check the result of `Env::IsExceptionPending` before 76attempting to use the returned value. 77 78[`Napi::ArrayBuffer`]: ./array_buffer.md 79[`Napi::Int32Array`]: ./typed_array_of.md 80[`Napi::Object`]: ./object.md 81[`Napi::TypedArray`]: ./typed_array.md 82