Arrays of Objects: For each element in array 1, does an object value exist as a value in any of the objects in array 2

Posted by DevOtts on Stack Overflow See other posts from Stack Overflow or by DevOtts
Published on 2014-08-22T04:05:14Z Indexed on 2014/08/22 4:20 UTC
Read the original article Hit count: 213

Filed under:
|
|

I have two arrays which contain objects in each element of the array.

var array1 = [{firstName: "John", lastName: "McDonald"}, {firstName: "Sandy", lastName: "Johnson"},....,]
var array2 = [{userName: "Donald"}, {userName: "John"},....,]

In psuedo-code, I want to do the following:

for each element in array1, is array1[i].firstName == to any of the userName's in array2. In plain english I want to look at each firstname in array1 and see if it exists at all in array2 as the value associated with the userName property.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about arrays