views:

112

answers:

2

i've managed to serialze a Dictionary collection. I return it from the webservice to jQuery ajax as a string then i place the return value into the javascript variable that i've declared as an array:

var myHistoryList = {};

....
success: function(retVal) {
                    myHistoryList = retVal.d;                   
                }

Then I attempt to loop through it, it seems to be not getting the right value. instead its displaying jQuery code like this:

trimStart  function(){return this.replace(/^\s+/,"")} 

which is pretty weird to me.

Heres my javascript for-loop:

for (var yahoo in myHistoryList) {
                    $('#myUseTable > tbody:last')
                        .append('<tr><td>' + [yahoo] +
                                '</td><td>' + myHistoryList[yahoo] +
                                '</td>');
                };

Help!

A: 

jQuery or another library you've included has extended the prototype of Object so all objects have extra helper functions included. You can use the hasOwnProperty function in your for loop to check for that condition:

for (var key in myHistoryList) {
    if (myHistoryList.hasOwnProperty(key)) {
        // do your thing
    }
}
Jacob
A: 

you should also be able to do a for loop like so:

for (var i=0; i < myHistoryList.length; i++) {
   alert(myHistoryList[i].SomeProperty);
}
Jeff T