title: Comparing two arrays and filtering one array upon this in javascript and react
body: <p>I am trying to compare two arrays of objects as following :</p>
  <pre><code>const obj1 = [
          {name:&quot;Mark&quot;},
          {name:&quot;David&quot;},
          {name:&quot;Ellie&quot;},
          {name:&quot;Zuank&quot;},
          {name:&quot;Philip&quot;},
          {name:&quot;Den&quot;},
      ]
      const obj2 = [
          {name:&quot;Mark&quot;},
          {name:&quot;David&quot;},
          {name:&quot;Zuank&quot;},
          {name:&quot;Philip&quot;},
      ]
  </code></pre>
  <p>I want to check if the name of every object exists in the second object or not. If yes, I want to push that object to a new array with a new property named &quot;Matched&quot; added to each object with a value of &quot;true&quot;. Otherwise, the Matched property will be false. This is the final result I want to achieve :</p>
  <pre><code>  const res = [
          { name: &quot;Mark&quot;, matched: true },
          { name: &quot;David&quot;, matched: true },
          { name: &quot;Ellie&quot;, matched: false },
          { name: &quot;Zuank&quot;, matched: true },
          { name: &quot;Philip&quot;, matched: true },
          { name: &quot;Den&quot;, matched: false },
      ]
  </code></pre>
  <p><strong>--Edit</strong>
  Here is what I have tried so far guys :</p>
  <pre><code>obj1.map((element, index) =&gt; {
          if (obj2[index].name === element.name) {
              resArr.push({ name: element.name, matched: true })
          }
          else {
              resArr.push({ name: element.name, matched: false })
          }
      })
  </code></pre>