title: Get only the objects whom particular property is fulfilled in JavaScript
body: <p>Having this array of objects:</p>
  
  <pre><code>myArray = [
      {name: "aaa", type: "1"},
      {name: "bbb", type: "2"},
      {name: "aaa", type: "3"},
      {name: "ddd", type: "1"},
      {name: "xxx", type: "3"},
      {name: "bbbb", type: "1"},
  ];
  </code></pre>
  
  <p>All this data is shown in a table. I'm implementing a drop-down selector which contains the list of <code>type</code>. </p>
  
  <p>I want to be able to show in the table only the objects respecting the condition.</p>
  
  <p>For example, if there is selected <code>1</code> from the selector it should show in the table this data:</p>
  
  <pre><code>{name: "aaa", type: "1"},
  {name: "ddd", type: "1"},
  {name: "bbbb", type: "1"},
  </code></pre>
  
  <p>For now, I have written function but it's not working.</p>
  
  <pre><code>updateTable(type) {
      const newArray = [];
      if (type === 1) {
          for (let i =0; i&lt; myArray.length; i++) {
              if (myArray[i].type === 1) {
                  newArray.push({myArray[i]});
              }
          }
      }
      if (type === 2) {
          for (let i =0; i&lt; myArray.length; i++) {
              if (myArray[i].type === 2) {
                  newArray.push({myArray[i]});
              }
          }
      }
      if (type === 3) {
          for (let i =0; i&lt; myArray.length; i++) {
              if (myArray[i].type === 3) {
                  newArray.push({myArray[i]});
              }
          }
      }
      return newArray;
  
  }
  </code></pre>
  
  <p>I tried to do it by creating a new array which isn't the best way. Is there a solution without creating a new array?</p>