I have a JavaScript object called data. I am using the following code to sort the keys in the object :
var index = [];
// build the index
for (var x in data) {
index.push(x);
}
// sort the index
index.sort(function (a, b) {
return a == b ? 0 : (a > b ? 1 : -1);
});
I then want to access the value for a particular index key in the following way :
for (var i=0; i<index.length; i++) {
var key = index[i];
document.getElementById(key).value = data.key;
}
However I am getting undefined for the data.key value. Can anyone suggest why ?
for()construct, it can't be a string.