I'm having trouble wrapping my mind around javascript hashmaps and JSON arrays. I'm trying to count duplicate import countries from a JSON array. For instance the data is:
[
{
"id": 1,
"import_country": "Russia",
"model": "Express 2500",
"make": "Chevrolet",
"sold_by": "Sibylla Kneale",
"sale_price": 14702
},
{
"id": 2,
"import_country": "Philippines",
"model": "G-Class",
"make": "Mercedes-Benz",
"sold_by": "Gabie Gradwell",
"sale_price": 19142
},
{
"id": 3,
"import_country": "Russia",
"model": "M",
"make": "Infiniti",
"sold_by": "Burl Pitkeathley",
"sale_price": 18395
}
]
This is what I have for code so far:
var country = [];
var temp = [];
const model = [];
const count = 0;
const response = await fetch('some api url where data is retrieved')
.then(response => response.json())
.then(data => {
var key = {};
for(i = 0; i< data.length; i++){
if(temp.indexOf(data[i].import_country) == -1){
temp.push(data[i][import_country]);
var _data = {};
}
}
});
My end goal is to have the total country count displayed on a graph.