Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: How to loop through IEnumerable in javascript

$
0
0
Hello ClearScript,

I have a host object ProductManager and it provides a function to search products:
public IEnumerable<Product> Search(string condition);
How can I loop through the IEnumerable result in JavaScript likes following:
In C#:
ProductManager manager = new ProductManager();
engine.AddHostObject("productManager", manager );
engine.AddHostType("console", typeof(Console));
In JavaScript:
var results = productManager.Search("price > 100");
for (XXXXXXXX)   <- how to write the for statement here?
{
     ......
}
Should I use the ToArray() first just likes the following?
var results = productManager.Search("price > 100").ToArray();
for (var i = 0; i < results.Length; i++)
{
    console.WriteLine(results[i].Name);
}

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images