Skip navigation

I had an issue today where I wanted to get the keys from an array (they were not not known to me and were variable) and assign them as a property to an object.

Turns out the solution was very simple.

var result = results[i];
for (var key in result) {
   row.prop(key, result[key]);
}

 

Since I couldn’t access the value by ‘results[i].key’, I assigned results[i] to result. Then accesses it by results[key]. This is due to how javascript really stores things.

Leave a Reply

Your email address will not be published. Required fields are marked *