1.1.0 • Published 8 years ago

pick-to-array v1.1.0

Weekly downloads
15
License
MIT
Repository
github
Last release
8 years ago

pick-to-array

Pick all values of a property in one or more objects

Made with ❤ at @outlandish

js-standard-style

Install

npm install --save pick-to-array

Import

// ES6
import pickToArray from 'pick-to-array'

// CommonJS
var pickToArray = require('pick-to-array')

// RequireJS
define(['pick-to-array'], function (pickToArray) {/*...*/})
<!-- Script, available as `window.pickToArray` -->
<script src="/node_modules/pick-to-array/index.js"></script>

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:

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!

Author & License

pick-to-array was created by Sam Gluck and is released under the MIT license.