Skip to content

How can I convert C# arrays to JS arrays? #601

Answered by ClearScriptLib
Soundman32 asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @Soundman32,

I also want to iterate over this collection, but this also fails.

Enumerable .NET objects are iterable from JavaScript, so you can do this:

for (const item of _myObject.GetItems()) {
    // do something
}

How can I convert C# arrays to JS arrays?

Because .NET arrays are iterable, you can use JavaScript's Array.from. You can even call it directly from the host:

var jsArray = engine.Script.Array.from(dotNetArray);

Good luck!

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Soundman32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants