Get the value for a property of an associative array when the property name is an integer:
Starting with an associative array, where the property names are integers:
var categories = [ {"1":"Category 1"}, {"2":"Category 2"}, {"3":"Category 3"}, {"4":"Category 4"} ];
Move items to array:
categories.push({"2300": "Category 2300"}); categories.push({"2301": "Category 2301"});
Scroll through the array and do something with the property value.
for (var i = 0; i < categories.length; i++) { for (var categoryid in categories[i]) { var category = categories[i][categoryid];
The console output should look like this:
1 : Category 1 2 : Category 2 3 : Category 3 4 : Category 4 2300 : Category 2300 2301 : Category 2301
As you can see, you can bypass the association array constraint and have the property name as a whole.
NOTE. The associative array in my example is json, which you would have if you serialized the Dictionary <string, string> [] object.
Jason Williams Jun 15 '15 at 16:33 2015-06-15 16:33
source share