Question: I have an array of objects like so:

```js
    [
      {
        id: 'a',
        name: 'Alan',
        age: 10
      },
      {
        id: 'ab'
        name: 'alanis',
        age: 15
      },
      {
        id: 'b',
        name: 'Alex',
        age: 13
      }
    ]

```

I need to pass an object like this `{ id: 'a', name: 'al' }` so that it does a wildcard filter and returns an array with the first two objects.

So, the steps are:

1. For each object in the array, filter the relevant keys from the given filter object
2. For each key, check if the value starts with matching filter object key's value

At the moment I'm using lodash's filter function so that it does an exact match, but not a start with/wildcard type of match. This is what I'm doing:

`filter(arrayOfObjects, filterObject)`

Answer: 
You can create a custom method that receives and object with pairs of `(key, regular expression)` and inside the [Array.filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) iterater over the [Object.entries()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries) to check for some match.

```js
let input = [
  {id: 'a', name: 'Alan', age: 10},
  {id: 'ab', name: 'alanis', age: 15},
  {id: 'b', name: 'Alex', age: 13}
];

const filterWithSome = (arr, obj) =>
{
    return arr.filter(o =>
    {
        return Object.entries(obj).some(([k, v]) => o[k].match(v));
    });
}

console.log(filterWithSome(input, {id: /^a/, name: /^al/}));
```

```css
.as-console {background-color:black !important; color:lime;}
.as-console-wrapper {max-height:100% !important; top:0;}
```

If you instead want a match on every `(key, regular expression)` of the object passed as argument, then you can replace [Array.some()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some) by [Array.every()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every):

```js
let input = [
  {id: 'a', name: 'Alan', age: 10},
  {id: 'ab', name: 'alanis', age: 15},
  {id: 'b', name: 'Alex', age: 13}
];

const filterWithEvery = (arr, obj) =>
{
    return arr.filter(o =>
    {
        return Object.entries(obj).every(([k, v]) => o[k].match(v));
    });
}

console.log(filterWithEvery(input, {id: /^ab/, name: /^al/}));
```

```css
.as-console {background-color:black !important; color:lime;}
.as-console-wrapper {max-height:100% !important; top:0;}
```
For the dynamic object filter. You can you `closure` and `reduce`

```js
const data = [
  {id: 'a',name: 'Alan',age: 10},
  {id: 'ab',name: 'alanis',age: 15},
  {id: 'b',name: 'Alex',age: 13}
]

const queryObj = { id: 'a', name: 'al' }
const queryObj2 = { name: 'al', age: 13 }

const filterWith = obj => e => { 
  return Object.entries(obj).reduce((acc, [key, val]) => {
    if(typeof val === 'string') return acc || e[key].startsWith(val)
    else return acc || e[key] === val
  }, false)
}

const filter1 = filterWith(queryObj)
const filter2 = filterWith(queryObj2)

console.log(data.filter(filter1))
console.log(data.filter(filter2))
```