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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -