How can I convert C# arrays to JS arrays? #601
-
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? |
Beta Was this translation helpful? Give feedback.
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! |
Beta Was this translation helpful? Give feedback.
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!