1.0.1 • Published 6 years ago

lodash-only v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Lodash only

Build Status Known Vulnerabilities NPM version

Extend Lodash to take an array of objects and the name of a property and return an array containing only the unique values of that property. Returns a new array with the original array left unchanged.

_.only(arr, property)

Arguments
arr (array): The array of objects to be examined. Required.
property (string): The name of the property we are seeking the unique values of. Required.

Returns
(array): An array of the unique values of property. The order of result values is determined by the order they occur in the input array.

Examples

var _ = require('lodash')
require('lodash-only')

_.only([{a:12, b:5}, {a:6}, {a:12, b:999}],'a') // [12,6]
_.only([{a:'ABC1', b:5}, {a:'DEF'}, {a:'ABC1', b:999}], 'a') // ['ABC1','DEF']
_.only([{a:'ABC'}, {a:'DEF'}, {a:'abc'}], 'a') // ['ABC','DEF','abc']
_.only( [{a:'ABC'}, {a:12}, {a:'DEF'}], 'a') // ['ABC',12,'DEF']
_.only([], 'a') // []
_.only([{a:'ABC', b:5}, {a:'DEF'}, {a:'ABC', b:999}], 'z') // []
_.only([{a:'ABC'}, {a:'DEF'}, {b:999}, {a:'ZZZZ'}], 'a') // ['ABC','DEF','ZZZZ']

Version History

VersionRelease DateDetails
1.0.127th February, 2018Cosmetic fix to README. No functionality changes.
1.0.027th February, 2018Initial release.