javascript - How to iterate structures properly -


i'd iterate found structures don't know way best this.

i've tried one:

for (var ext in creep.room.find(find_my_structures, {filter: { structuretype: structure_extension }})){     console.log(ext.energy); } 

but doesn't work.

so i'm using approach works, looks ugly:

for(var = 0; < creep.room.find(find_my_structures, {filter: { structuretype: structure_extension }}).length; i++) {     var ext = creep.room.find(find_my_structures, {filter: { structuretype: structure_extension }})[i];     console.log(ext.energy); } 

i'm not sure, maybe question related js. i'm newbie in js. can advice this?

ext contains key, not value of result.

so have done, move results out of loop , put in variable called results. way, have variable reference in loop.

so whats going on that, because ext in code storing key, string type value. returning results string object, you're doing "key".energy , returns value undefined, because string object doesn't have key that.

so here below code should work:

var results = creep.room.find(find_my_structures, {filter: { structuretype: structure_extension }}); (var ext in results){     console.log(results[ext].energy); } 

Comments

Popular posts from this blog

symfony - TEST environment only: The database schema is not in sync with the current mapping file -

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -