How can I convert C# arrays to JS arrays? #601
Answered
by
ClearScriptLib
Soundman32
asked this question in
Q&A
|
I have a C# method that returns a collection: public IList GetItems()
{
...
return collection.ToArray();
}In the JS code, I can't use I also want to iterate over this collection, but this also fails. const items = _myObject.GetItems();
items.forEach(async item => { } );How can I convert C# arrays to JS arrays? |
Answered by
ClearScriptLib
Sep 15, 2024
Replies: 1 comment
|
Hello @Soundman32,
Enumerable .NET objects are iterable from JavaScript, so you can do this: for (const item of _myObject.GetItems()) {
// do something
}
Because .NET arrays are iterable, you can use JavaScript's var jsArray = engine.Script.Array.from(dotNetArray);Good luck! |
0 replies
Answer selected by
Soundman32
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello @Soundman32,
Enumerable .NET objects are iterable from JavaScript, so you can do this:
Because .NET arrays are iterable, you can use JavaScript's
Array.from. You can even call it directly from the host:Good luck!