c++node.jsnode.js-napi

Iterate Napi::Object Properties (Keys) in Node.js C++ N-API


I am having a problem using c++ n-api api and I have reviewed the documentation here, and I do not see a way to iterate the keys of a Napi::Object. I must be missing something because this is possible in JavaScript, so it must be possible in the C++ API.

How can I list or iterate the keys (properties) in a Napi::Object.


Solution

  • It seems the Doxygen documentation which Google surfaced at https://nodejs.github.io/node-addon-api/ is out-of-date.

    The right place to look is on the Node.js Github repo at https://github.com/nodejs/node-addon-api/blob/master/napi.h

    Looking at the correct header version, Napi::Object has a function GetPropertyNames() which is exactly what I needed (though it is oddly not const).