Skip to content
Advertisement

JavaScript lookup: update value of object in array if object key exists in another object array similar to the v-lookup in excel

Just trying to update the dates in array2 if ID matches in array1 so that they are not null.

JavaScript

Desired output:

JavaScript

How do I use a loop with the indexof() method?

Advertisement

Answer

You could use a map method to iterate trough the second array, find an element with the same id in the first array and take the date from there:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement