Jayesh Jayesh - 1 year ago 131
Node.js Question

Using Nan to create array in Node.js add-on code

I'm writing Node add-on and using the nan library as much as I can for writing the code. It's recommended by the Node project because it lets you write code that's compatible with different version of v8 and node.

However after looking through their documentation many times, I haven't found any guidance on handling of arrays in the nan API. For basic tasks like processing arrays passed as arguments by the Javascript code, or instantiating new array objects in the add-on and return it to Javascript code. Are we supposed to directly work with

API. I wished the Nan::New part of the API would have handled this better.

Have I missed something?

Answer Source

If you look at the V8 documentation, you'll see that v8::Array is a subset of v8::Object. Given this, you can create an array with


You can reference the v8::Array documentation for more details.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download