# Get the unique properties of objects in a JavaScript array

> Learn how to extract the unique values of a property from an array of objects in JavaScript, combining map() with a Set and the spread operator.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2018-09-28 | Topics: [JavaScript](https://flaviocopes.com/tags/js/) | Canonical: https://flaviocopes.com/how-to-get-unique-properties-of-object-in-array/

Suppose you have a bills array with this content:

```js
const bills = [
  { date: '2018-01-20', amount: '220', category: 'Electricity' },
  { date: '2018-01-20', amount: '20', category: 'Gas' },
  { date: '2018-02-20', amount: '120', category: 'Electricity' }
]
```

and you want to extract the unique values of the `category` attribute of each item in the array.

Here's what you can do:

```js
const categories = [...new Set(bills.map(bill => bill.category))]
```

## Explanation

[Set](https://flaviocopes.com/javascript-data-structures-set/) is a new data structure that [JavaScript](https://flaviocopes.com/javascript/) got in [ES6](https://flaviocopes.com/es6/). It's a collection of unique values. We put into that the list of property values we get from using `map()`, which how we used it will return this array:

```js
['Electricity', 'Gas', 'Electricity']
```

Passing through Set, we'll remove the duplicates.

`...` is the [**spread operator**](https://flaviocopes.com/javascript-spread-operator/), which will expand the set values into an array.
