Create a new object that excludes specified keys I have 2 data structures with me in JS. One is an array say of length N. Let's consider N = 4.

const arr = ['a', 'b', 'c', 'd'];


The second one is an object:

const obj = {
  a: 0,
  b: 2,
  c: 3,
  z: 5
};


I wrote a code in Javascript, to create a new object out of obj which should not contain the keys which are not present in the array arr. As of now, the time complexity of the code is \$O(n*n)\$ i.e., \$O(4*4)\$. 

standardizeFilter(queryParams: any, inputType: Array&lt;string&gt;) {
  const filter = {};

  for (const key of Object.keys(queryParams)) {
    if (inputType.indexOf(key) &gt; -1) {
      filter[key] = this.parseValues(queryParams[key]);
    }
  }
  return filter;
}


I'm wondering if there is a much optimal way to convert this \$O(n²)\$ to \$O(n)\$.
From a short review;


Naming


standardizeFilter is too specific/specialized, perhaps standardizeObject?
queryParams also seems a very specific name, whereas the functionality is very general, I would just call it keys
inputType is not a type, it's an object, I would propose source

For each key you perform both a indexOf and a [] access, you can drop the indexOf


I would propose something like this:

function standardizeObject(source, keys){

  const o = {};

  for(const key of keys){
    const value = source[key];
    if(value !== undefined){
      o[key] =  this.parseValues(value);
    }
  } 

  return o;
}