Is there a way to use a JavaScript variable to retrieve a specific item from an array stored in a model?
Below is a code snippet:
function CreateCategoryList()
{
var limit = @(Model.CategoriesCount.ToString());
for (i=0; i<limit; i++)
{
var category = '<div class="CategoryItem">' + '@(Model.CategoryList[i].Name.ToString())' + '</div>';
$("#CategoriesPopup").append(category);
}
alert($(".CategoryItem:first").text());
}
I'm trying to access the i-th item in Model.CategoryList using the i variable in the for loop. Can anyone help with this?