https://github.com/bjarneo/object-column
Return a single column from an array of objects
https://github.com/bjarneo/object-column
array column object
Last synced: 10 months ago
JSON representation
Return a single column from an array of objects
- Host: GitHub
- URL: https://github.com/bjarneo/object-column
- Owner: bjarneo
- License: mit
- Created: 2017-02-01T20:38:57.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-08T06:59:20.000Z (over 9 years ago)
- Last Synced: 2025-07-05T07:51:35.825Z (10 months ago)
- Topics: array, column, object
- Language: JavaScript
- 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
object-column
--

Return the values from a single column from the array of objects
Install
--
```js
$ npm i --save object-column
```
Usage
--
```js
const objectColumn = require('object-column');
objectColumn(
array, // Your array with objects
column, // The column you want to fetch
key // Optional. Key for your returned object
);
```
```js
const data = [{
id: 1,
name: 'Nanon',
repository: 'https://github.com/bjarneo/nanon'
}, {
id: 2,
name: 'Instantly',
repository: 'https://github.com/bjarneo/instantly'
}, {
id: 3,
name: 'Roc',
repository: 'https://github.com/rocjs/roc'
}, {
id: 4,
name: 'Object Column',
repository: 'https://github.com/bjarneo/object-column'
}];
const names = objectColumn(data, 'name');
// [ 'Nanon', 'Instantly', 'Roc', 'Object Column' ]
const nameRepo = objectColumn(data, 'repository', 'name');
/*
[{
Nanon: 'https://github.com/bjarneo/nanon'
}, {
Instantly: 'https://github.com/bjarneo/instantly'
}, {
Roc: 'https://github.com/rocjs/roc'
}, {
'Object Column': 'https://github.com/bjarneo/object-column'
}]
*/
```
Contribution
--
Contributions are appreciated.
License
--
MIT-licensed. See LICENSE.