# filter-obj

> Filter object keys and values into a new object

Latest version **6.1.0** (published 2024-05-27) · MIT license · 0 weekly downloads

> **Better alternative:** Use Object.fromEntries(Object.entries(obj).filter(fn)) — Consider using a lighter alternative

## Install

```sh
npm install filter-obj
pnpm add filter-obj
yarn add filter-obj
bun add filter-obj
```

## Health

**Score 45/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 6.1.0 |
| Published | 2024-05-27 |
| First published | 2015-08-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=18 |
| Dependencies | 0 |
| Unpacked size | 6.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 105 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | filter, object, key, keys, value, values, iterate, iterator, include, exclude, pick, omit |

## Links

- npm: https://www.npmjs.com/package/filter-obj
- Repository: https://github.com/sindresorhus/filter-obj
- Homepage: https://github.com/sindresorhus/filter-obj#readme
- Issues: https://github.com/sindresorhus/filter-obj/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/filter-obj

## Recent versions

- 6.1.0 (latest) — 2024-05-27
- 6.0.0 — 2024-03-11
- 5.1.0 — 2022-07-30
- 5.0.0 — 2022-07-26
- 4.0.0 — 2022-07-23
- 3.0.0 — 2021-08-26
- 2.0.2 — 2021-04-06
- 2.0.1 — 2019-10-04
- 2.0.0 — 2019-04-22
- 1.1.0 — 2015-08-12
- 1.0.0 — 2015-08-10

## README

# filter-obj

> Filter object keys and values into a new object

## Install

```sh
npm install filter-obj
```

## Usage

```js
import {includeKeys, excludeKeys} from 'filter-obj';

const object = {
	foo: true,
	bar: false
};

const newObject = includeKeys(object, (key, value) => value === true);
//=> {foo: true}

const newObject2 = includeKeys(object, ['bar']);
//=> {bar: false}

const newObject = excludeKeys(object, (key, value) => value === true);
//=> {bar: false}

const newObject3 = excludeKeys(object, ['bar']);
//=> {foo: true}
```

## API

### includeKeys(source, filter)
### includeKeys(source, keys)
### excludeKeys(source, filter)
### excludeKeys(source, keys)

#### source

Type: `object`

The source object to filter properties from.

#### filter

Type: `(sourceKey: string | symbol, sourceValue: unknown, source: object) => boolean`

A predicate function that determines whether a property should be filtered.

#### keys

Type: `Array<string | symbol> | Set<string | symbol>`

An array or [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) of property keys to be filtered.

## Related

- [map-obj](https://github.com/sindresorhus/map-obj) - Map object keys and values into a new object

---
_Source: https://npm.io/package/filter-obj · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
