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

gcc - MinGW's ld cannot perform PE operations on non PE output file -

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

c# - Search and Add Comment with OpenXML for Word -