title: How can I update an array based on another array on matching index?
body: <p>I have the following two object arrays.  I would like to update array1 elements to reflect array2 elements where the transid matches.  So my result should be either a new array that has the two elements from array1 updated to reflect the values in array2, or the same array1 with the updated values.</p>
  
  <p>What is the best way to do that with some of the more modern syntax?  I open to several options so I can compare.  For example, I'm guessing matching objects in array1 can just be replaced with array2 objects or the individual elements within the array1 objects can be updated through some sort of iteration over the elements.</p>
  
  <pre><code>var arra1 = [{
      "_id" : ObjectId("583f6e6d14c8042dd7c979e6"),
      "transid" : 1,
      "acct" : "acct1",
      "transdate" : ISODate("2012-01-31T05:00:00.000Z"),
      "category" : "category1",
      "amount" : 103 
  }, {
      "_id" : ObjectId("583f6e6d14c8042dd7c2132t6"),
      "transid" : 2,
      "acct" : "acct2",
      "transdate" : ISODate("2012-01-31T05:00:00.000Z"),
      "category" : "category2",
      "amount" : 103 
  }]
  
  var arra2 = [{
      "_id" : ObjectId("583f6e6d14c8042dd7c979e6"),
      "transid" : 1,
      "acct" : "acct2",
      "transdate" : ISODate("2012-01-31T05:00:00.000Z"),
      "category" : "category5",
      "amount" : 107 
  }, {
      "_id" : ObjectId("583f6e6d14c8042dd7c2132t6"),
      "transid" : 2,
      "acct" : "acct2",
      "transdate" : ISODate("2012-01-31T05:00:00.000Z"),
      "category" : "category2",
      "amount" : 103 
  }, {
      "_id" : ObjectId("583f6e6d14c8042dd7c2132t6"),
      "transid" : 3,
      "acct" : "acct2",
      "transdate" : ISODate("2016-07-31T05:00:00.000Z"),
      "category" : "category3",
      "amount" : 103 
  }]
  </code></pre>
  
  <p>I played with it a bit and have something like this thus far.  It's not working but that's the type of logic I'm looking for.</p>
  
  <pre><code>arr1.forEach(item =&gt; 
    if (arr2.indexOf(item.transid) != -1){
      item.category = arr2.indexOf(item.transid).category
    }
  )
  </code></pre>