samedi 14 février 2015

How do you search object for a property within property?


I have this object:



key = {
spawn:{type:1,img:app.assets.get('assets/spawn.svg')},
wall:{type:2,img:app.assets.get('assets/wall.svg')},
grass:{type:3,img:app.assets.get('assets/grass.svg')},
spike:{type:4,img:app.assets.get('assets/spike.svg')},
ground:{type:5,img:app.assets.get('assets/ground.svg')}
};


And I have an array with only types and I need to add the given image to it, the array looks something like this:



[{type:1,image:null},{type:3,image:null},{type:2,image:null},{type:2,image:null},{type:5,image:null}]


Basically I want to loop the array, find the type in the key object and get the given image and save it into the array.


Is there any simple way to do this?





Aucun commentaire:

Enregistrer un commentaire