https://github.com/sdgluck/pick-to-array
:ant: Pick all values of a property in one or more objects
https://github.com/sdgluck/pick-to-array
Last synced: 9 months ago
JSON representation
:ant: Pick all values of a property in one or more objects
- Host: GitHub
- URL: https://github.com/sdgluck/pick-to-array
- Owner: sdgluck
- License: mit
- Created: 2016-07-24T19:17:04.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-09-25T11:11:02.000Z (over 9 years ago)
- Last Synced: 2025-08-09T13:30:33.617Z (10 months ago)
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pick-to-array
> Pick all values of a property in one or more objects
Made with ❤ at [@outlandish](http://www.twitter.com/outlandish)
[](http://standardjs.com/)
## Install
```sh
npm install --save pick-to-array
```
## Import
```js
// ES6
import pickToArray from 'pick-to-array'
// CommonJS
var pickToArray = require('pick-to-array')
// RequireJS
define(['pick-to-array'], function (pickToArray) {/*...*/})
```
```html
```
## Usage
### `pickToArray(entities, property[, deep])`
Pick all values of a property in one or more objects.
- __entities__ {Array|Object} Entities or entity to pick from
- __property__ {String|Array} Property name(s) to pick value from
- [__deep__] {Boolean} Pick from nested properties
Returns an array of all the values.
Example:
```js
const entities = [{ id: 456 }, { id: 789 }, { entity: { id: 123 } }]
const ids = pickToArray(entities, 'id', true)
console.log(ids) //=> [456, 789, 123]
```
## Contributing
All pull requests and issues welcome!
If you're not sure how, check out Kent C. Dodds'
[great video tutorials on egghead.io](https://egghead.io/lessons/javascript-identifying-how-to-contribute-to-an-open-source-project-on-github)!
## Author & License
`pick-to-array` was created by [Sam Gluck](https://twitter.com/sdgluck) and is released under the MIT license.