I am fetching data from a big API with a lot of data. There is a lot of data with same building names that I need to output but I don't want all data to repeat itself I only want to display unique data.
How can I accomplish this?
var data = {
"data": [{
"id": 1,
"building": "Big Building"
}, {
"id": 2,
"building": "Big Building"
}, {
"id": 3,
"building": "Small Building"
}, {
"id": 4,
"building": "Small Building"
}]
}
jQuery.each(data.data, function(index, item) {
console.log(this['building']);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Result:
Big Building
Big Building
Small Building
Small Building
Wanted result:
Big Building
Small Building
idshould be kept? The first one found, or the last? Or do you not want to keep theidproperties at all?