Conclusion limited data from an array?

Hi,
There is a json array
[{'id':1, 'name':'John', 'collection':'boston'},
{'id':2, 'name':'Faer', 'collection':'antler'},
{'id':3, 'name':'klei', 'collection':'aqua'},
{'id':4, 'name':'Inda', 'collection':'boston'},
{'id':5, 'name':'Faer', 'collection':'antler'}];


As a means for() to js display a list of collections (collection),
to get a list like this:

boston
antler
aqua


Which are collections only 3, but in the mountains they are specified several times, and I need to get only 3.
June 5th 19 at 21:36
2 answers
June 5th 19 at 21:38
const collections = []
for (let i = 0; i < data.length; i++) {
 if (!collections.includes(data[i].collection)) {
collections.push(data[i].collection);
}
}

const collections = Array.from(new Set(data.map(d => d.collection)));

const collections = Object.keys(data.reduce((res, next) => {
 res[next.collection] = null;
 return res;
}, {}));

const collections = data.reduce((res, next) => {
 if (!Res. includes(next.collection)) {
Res. push(next.collection);
}
 return res;
}, {});
June 5th 19 at 21:40
var json = [{'id':1, 'name':'John', 'collection':'boston'},
{'id':2, 'name':'Faer', 'collection':'antler'},
{'id':3, 'name':'klei', 'collection':'aqua'},
{'id':4, 'name':'Inda', 'collection':'boston'},
{'id':5, 'name':'Faer', 'collection':'antler'}];

var result = new Set();

for (var i = 0; i < json.length; i++) {
result.add(json[i].collection);
}

console.log(result);

Find more questions by tags JavaScript