I am working with a DropDownList and have a requirement to store values in a javascript variable before setting it on the DropDown. I need to loop through the values and format them as shown below:
var categories = [{
"value": 1,
"text": "Keyboard"
},{
"value": 2,
"text": "Mouse"
},{
"value": 3,
"text": "Monitor"
}];
A sample code snippet that I tried is:
dataType: "json",
data: { categoryId: CategoryHdId },
success: function (data) {
var categories = [];
for (i = 0; i < data.length; i++) {
case = {
"value": data[i].ddlSubCategoryId,
"text": data[i].SubCategoryName
}
categories.append(case);
}
}
However, this results in a
Syntax Error
and
Uncaught TypeError: categories.append is not a function
I would appreciate any help or suggestions on how to properly set the values inside the loop.