> For the complete documentation index, see [llms.txt](https://worn.gitbook.io/json-function/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://worn.gitbook.io/json-function/functions/where.md).

# Where

[Github](https://github.com/aykutkardas/Json-Function) repository for your stars.

## Usage

#### Install

```bash
$ npm install json-function
```

#### Import

```javascript
import { where } from 'json-function';
```

#### Usage

Example Data

```javascript
const data = [
  {
    id: 1,
    userId: 1,
    title: "delectus aut autem",
    completed: false,
    education: {
      isDone: true
    }
  },
  {
    id: 2,
    userId: 1,
    title: "lorem ipsum",
    completed: true,
    education: {
      isDone: true
    }
  },
  {
    id: 3,
    userId: 2,
    title: "quis ut nam facilis et officia qui",
    completed: false,
    education: {
      isDone: false
    }
  }
];
```

### Basic Syntax

```javascript
where(data, { userId: 1 });
```

Output

```javascript
[
  {
    id: 1,
    userId: 1,
    title: "delectus aut autem",
    completed: false,
    education: {
      isDone: true
    }
  },
  {
    id: 2,
    userId: 1,
    title: "lorem ipsum",
    completed: true,
    education: {
      isDone: true
    }
  }
];
```

### AND Syntax

```javascript
where(data, { userId: 1, completed: true });
```

Output

```javascript
[
  {
    id: 2,
    userId: 1,
    title: "lorem ipsum",
    completed: true,
    education: {
      isDone: true
    }
  }
];
```

### OR Syntax

```javascript
where(data, [{ userId: 1, completed: true }, { userId: 2, completed: false }]);
```

Output

```javascript
[
  {
    id: 2,
    userId: 1,
    title: "lorem ipsum",
    completed: true,
    education: {
      isDone: true
    }
  },
  {
    id: 3,
    userId: 2,
    title: "quis ut nam facilis et officia qui",
    completed: false,
    education: {
      isDone: false
    }
  }
];
```

Use "callback" for advanced filter.

```javascript
// id <= 3
where(data, (wh) => ({
  id: wh.lte(3),
}));
```

Other **wh** methods.

```javascript
wh.lte(3)            // value <= 3
wh.lt(3)             // value <  3
wh.gte(3)            // value >= 3
wh.gt(3)             // value >  3
wh.between(3,5)      // value >= 3 && value <= 5
wh.eq("3")           // value == 3
wh.ne("3")           // value != 3
wh.in('test')        // value.includes('test')
wh.nin('test')       // !value.includes('test')
wh.oneOf([1, 2, 3])  // [1, 2, 3].includes(value)
```

### Deep Where Syntax

```javascript
where(data, { 'education.isDone': true }, { deep: true });
```

{% hint style="info" %}
&#x20;It is necessary to add a new option argument to use "Deep Where".

`{ deep: true }`
{% endhint %}

Output

```javascript
[
  {
    id: 1,
    userId: 1,
    title: "delectus aut autem",
    completed: false,
    education: {
      isDone: true
    }
  },
  {
    id: 2,
    userId: 1,
    title: "lorem ipsum",
    completed: true,
    education: {
      isDone: true
    }
  },
];
```
