Is there a better way to iterate over two array of objects than what I have done below? It seems messy to do it this way. I’m using lodash.
Since you’re using lodash, you could use the
_.find() method to find the corresponding object in
array2 based on the
It’s worth pointing out that this will result in an undefined
person property if an object isn’t found. If that’s a problem, simply check to see if an object is returned:
Without lodash, it would be pretty similar: