# @writetome51/get-property

> Allows you to retrieve value of object property using dot-notation in a string

Latest version **2.0.2** (published 2020-08-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @writetome51/get-property
pnpm add @writetome51/get-property
yarn add @writetome51/get-property
bun add @writetome51/get-property
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2020-08-27 |
| First published | 2019-02-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Steve Thompson |
| Maintainers | writetome51 |
| Keywords | get, object, property, value, dot, notation |

## Links

- npm: https://www.npmjs.com/package/@writetome51/get-property
- Repository: https://github.com/writetome51/get-property
- Homepage: https://github.com/writetome51/get-property#readme
- Issues: https://github.com/writetome51/get-property/issues
- npm.io page: https://npm.io/package/@writetome51/get-property

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 2.0.2 (latest) — 2020-08-27
- 2.0.1 — 2020-08-14
- 2.0.0 — 2020-08-02
- 1.0.4 — 2019-04-15
- 1.0.3 — 2019-03-16
- 1.0.2 — 2019-02-27
- 1.0.1 — 2019-02-02
- 1.0.0 — 2019-02-02

## README

# getProperty(property: string,  object): any

Why would you use this to get a property value instead of simply writing  
`object[property]` or `object.property` ?  
Because this function allows `property` to be a string that can include dot notation  
( i.e,  'property.subproperty.subsubproperty' ) .

Note:  even if you are getting the value of an array item, here you need to use  
dot-notation and not square braces.  
Example:  if getting the first item of the first item of an array, write:  
`getProperty('0.0', array);  // instead of array[0][0]`

## Examples
```
let officer = {name: {first: 'Tom', last: 'Arnold'}, rank: 'sergeant'};
let lastName = getProperty('name.last', officer);
// lastName === 'Arnold'

let city = {
	name: 'San Francisco', 
	cityCouncil: {
		members: [
			{name: {first: 'Megan', last: 'Trainor'}, age: 26},
			{name: {first: 'Justin', last: 'Bieber'}, age: 85}
		]
	}
};

let ageOfMeganTrainor = getProperty('cityCouncil.members.0.age',  city);
// ageOfMeganTrainor === 26
```

## Installation

You must have npm installed first.  Then, in the command line:

```bash
npm i @writetome51/get-property
```

## Loading
```js
import {getProperty} from '@writetome51/get-property';
```

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