I have to iterate two arrays, if the iso propery of the first array is equal to address.country of the second array condition is verified, assign address and slug of the second array (this.concessions) to the first array (this.countries).
At the end, you need to have a new this.countries array that contains the address and slug property (in addition to the properties he already had)
this.countries.map((element) => {
this.concessions.map((value) => {
if (element.iso === value.address.country) {
element.address = value.address
element.slug = value.slug
}
})
})
How can I optimize this, and for this case what is the best iterable to use, for ..of for example ?
mapif you don't return anything?forloop over amap. You may usefor ... ofif you want. It should work. If you really wanted fast performance, and are willing to sacrifice some memory, you can make an object/map where the keys are the countries and the values are the object from these arrays. That would introduce a constant time lookup, an only increase memory a little because the object/map would reference the objects in the array, not create a new object.