Question: I have an array of objects, example:

```
[
  {
    "fName": "Jon",
    "lName": "Doe",
    "age": "30",
    "shirtSize": "M"
  },
  {
    "fName": "Jane",
    "lName": "Foe",
    "age": "25",
    "shirtSize": "M"
  },
  ...
]

```

I also have a list of keys, example:

```
["age", "shirtSize"]

```

I want to take the array of objects, and build a new array of objects that match the key list array, effectively filtering the array of objects to only have the key/value pairs I want. The above are examples, and the real datasets are of course more verbose. I've brute forced it in my algorithm below and as expected, it's not very performant at all, as a result of my loop within the map. My result is like:

```
    [
      {
        "age": "30",
        "shirtSize": "M"
      },
      {
        "age": "25",
        "shirtSize": "M"
      },
      ...
    ]

```

I am not using anything like lodash. How can I improve this performance?

```
const data = [
  {
    "fName": "Jon",
    "lName": "Doe",
    "age": "30",
    "shirtSize": "M"
  },
  {
    "fName": "Jane",
    "lName": "Foe",
    "age": "25",
    "shirtSize": "M"
  }
];
const keyList = ["age", "shirtSize"];

const filteredDataset = data.map((elem) => {
  let tempHolder = {};
  for (let key of keyList) {
    tempHolder[key] = elem[key];
  }
  return tempHolder;
});

return filteredDataset;

```

Answer: 
From [the documentation](https://learn.microsoft.com/en-us/sql/t-sql/statements/set-identity-insert-transact-sql):

> 
> At any time, only one table in a session can have the `IDENTITY_INSERT` property set to `ON`.
> 
> 
> 

So, if you are in a batch where you want to override the auto-generated identity values on *two different* tables, you would set the first one to `OFF` before setting the second one to `ON`.

(Also, like a lot of things, if you change something from the default, it's never a bad idea to change it back.)
from <https://learn.microsoft.com/en-us/sql/t-sql/statements/set-identity-insert-transact-sql?view=sql-server-ver15>

> 
> At any time, only one table in a **session** can have the IDENTITY\_INSERT
> property set to ON. **If a table already has this property set to ON,
> and a SET IDENTITY\_INSERT ON statement is issued for another table,
> SQL Server returns an error message** that states SET IDENTITY\_INSERT is
> already ON and reports the table it is set ON for.
> 
> 
> 

so you should set it off before you set it on to another table in your session.