I am creating a JavaScript array that has strings as keys.
An array must have an object in each record. My object looks like this ( console.log my rIds variable):

Now the length of this object is 0, which makes it impossible to repeat it.
I want to iterate over each key, so I can get and access my list of identifiers ( rIds[key].productIds ).
The code
var rIds = []; var response = RR.data.JSON.placements; console.log(response); $(response).each(function (placementId) { var placement_name = this.placement_name; rIds[this.placement_name] = { productIds: [] }; $(this.recs).each(function (recIndex) { var pid = this.pid; pid = getRandomId(19341610, 19341746); rIds[placement_name].productIds[recIndex] = pid; }); }); var count = '<%=ViewBag.Get("RecommendationCount") %>'; console.log(rIds); console.log(rIds.length); $.each(rIds, function (index, val) { console.log(val);
What have i tried?
I found the following snippet that does not work in IE8. However, this does not really help, although Object.keys(rIds).length results in the correct length.
for (var index = 0; index < Object.keys(rIds).length; index++) { console.log(rIds[index]); }
However, this code does not make my access to the object.
Tl; dr and question
- How to iterate my JavaScript object that has strings as keys, so I can access individual records?
source share