title: Looping over two arrays in javascript simultaneously
body: <pre><code>let masterList=[{id:1,name:'Abc'},{id:2,name:'Def'},{id:3,name:'Ghi'}];
  let selectedList=[2,3];
  </code></pre>
  
  <p>The desired result is to have </p>
  
  <pre><code>//desiredList=[{id:2,name:'Def'},{id:3,name:'Ghi'}]
  </code></pre>
  
  <p>Currently what I am doing is</p>
  
  <pre><code>     let parsedArray = [];
        masterList.forEach(mItem =&gt; {
              selectedList.forEach(sItem =&gt; {
                  if (mItem.id === sItem) {
                      parsedArray.push(mItem);
                  }
              });
          });
       desiredList=parsedArray
  </code></pre>
  
  <p>I do not find this method efficient when iterating over large arrays, is there any logic, any inbuilt javascript operators using which I can achieve the same?</p>