javascript - Mapping object properties from one array to another -


i have 2 arrays (i'll call them thing1 , thing2), of same length, elements in different orders.

the elements can matched each other based on target , source names associated each element.

example matching elements each listed below:

thing1[0].target object {   name: "benthopelagics, large", parent: object, imports: array[7], tl: 3.717611213, b: 0.2… }  thing1[0].source object {   name: "outside", parent: object, imports: array[4], tl: 5.149219037, b: 0… }  thing2[216] object {source: "benthopelagics, large", target: "outside", value: 0.05800000596} 

i'd copy "value" field thing2 thing1, being newcomer javascript, haven't been able figure out how matching of source , target names.

can give me example of syntax required?

loop through thing2. each iteration of thing2 loop through thing1 , search matching object properties.

(demo)

for(var = 0, j = thing2.length; < j; i++) {     for(var k = 0, l = thing1.length; k < l; k++) {         if( thing1[k].source.name == thing2[i].source &&             thing1[k].target.name == thing2[i].target) {             thing1[k].value = thing2[i].value;         }     } } 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -