Skip to content

Array documentation #340

@rivertam

Description

@rivertam

So I'm pretty confused about how to use Arrays/TypedArrays using this library. Basically, I'm looking for the equivalent of the .push method. I'd also love a way to reserve space in chunks, as I know how big the resulting array is going to be, though that might be too complicated considering V8.

The documentation includes a .Set(int, Value) with the example obj.Set(42, "The Answer to Life, the Universe, and Everything");. This example is given for Object, not for Array (I can't find anything with Array at all).

I tried to do something similar in the code (I'm trying to make an array of arrays):

    obj.Set(0, Napi::Array::New(env));

but got the error:

error: call of overloaded ‘Set(int, Napi::Array)’ is ambiguous
     obj.Set(0, Napi::Array::New(env));

I'm very confused as to why that's ambiguous, but I also suspect it won't update the length properly or at least will be quite inefficient. When I wrap 0 in uint32_t(0), it compiles. Either way, the documentation here is pretty lacking and I think an example using arrays efficiently would be very welcome.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions