Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 3 days 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 (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-02-08T06:59:20.000Z (almost 8 years ago)
- Last Synced: 2024-10-13T23:06:51.276Z (about 1 month ago)
- Topics: array, column, object
- Language: JavaScript
- Size: 4.88 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
object-column
--
![Travis](https://travis-ci.org/bjarneo/object-column.svg?branch=master)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.