I don't think that this works, because then JavaScript probably will not be able to access the array elements by using testArray[i], does it?
The object I mentioned in the comment would be the easiest way, but you would not be able to access its elements as testArray[i]
from JavaScript.
The hard way would be implement a class in C# which simulates JavaScript array object (so it is exposed to JavaScript as COM IDispatchEx
object and is accessible as testArray[i]
). Such C# class would need to implement IReflect
and IExpando
managed interfaces. If you want to go this route, I posted some more details here:
Yet another way of doing this. Despite you cannot modify the page's existing JavaScript, you still can inject some new JavaScript code, and do with it whatever you want.