I created a NPAPI plugin and wants to access an array element in the plugin from Javascript. The javascript I used is the following one:
var foo_plug = document.getElementById('foo');
var elem = foo_plug.array_p[index];
PS:I got the hasProperty and getProperty methods of NPClass invoked when accessing a variable in a plugin and is working fine.
The first thing you need to understand is the calling chain. Let's look at the line in question:
var elem = foo_plug.array_p[index];
What this is going to do is first call NPN_GetProperty on the NPObject for foo_plug with an NPIdentifier that translates to the string "array_p".
What happens next depends on what is returned; if you return a string, index will be the index into that string. if it's an int, it'll give you an error. If, on the other hand, it's an NPObject, the next call will be NPN_GetProperty on that NPObject with an NPIdentifier that will either be an IntIdentifier (use NPN_GetIntIdentifier) or a string identifier with the number as a string (use NPN_IdentifierIsString to determine which).
Now, if the NPObject returned is an actual javascript array, you don't have to worry about that; you can get the NPObject for window and call Invoke on it with the identifier "Array" and no arguments and it will return an NPObject with an empty array; you can work with it to put things in it and return it and that will work fine.
Alternately, you can return an NPObject that supports the "length" property, NPN_Enumerate, and can intelligently handle either a numeric string identifier or an intidentifier (actually you need to handle both because some browsers use each type) and if it acts enough like a javascript array you probably won't know the difference.
FireBreath has excellent support for all of these options.