# 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
    }
  },
];
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://worn.gitbook.io/json-function/functions/where.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
