JSFiddle - React, Tailwind, and code Playground
JavaScript
var lang = 'nl',
response = {
"responseHeader":{
"status":0,
"QTime":1,
"params":{
"facet":"true",
"sort":"membervalue desc",
"fl":"id,city,thumb",
"facet.mincount":"1",
"indent":"on",
"start":"0",
"q":["*:*",
"*:*"],
"facet.field":["country_raw_nl",
"services_raw_nl",
"city"],
"wt":"json",
"fq":"country_nl:=australie",
"rows":"12"}},
"response":{"numFound":10,"start":0,"docs":[
{
"id":"842",
"city":"whitsundays",
"thumb":"735_739_CEREMONY-PAVILLION-2.jpg"}]
},
"facet_counts":{
"facet_queries":{},
"facet_fields":{
"country_raw_nl":[
"Australie",10],
"services_raw_nl":[
"In-house Catering",9,
"Live music",6],
"partylocation":[
"true",8,
"false",2],
"hasphoto":[
"true",9,
"false",1],
"hasvideo":[
"false",10],
"rating":[
"0.0",10],
"rating_rounded":[
"0.0",10],
"facet_dates":{},
"facet_ranges":{}
}
}
};
function getServices (response, lang) {
var services_raw = response.facet_counts.facet_fields['services_raw_' + lang],
n, temp = {};
for (n = 0; n < services_raw.length; n+= 2) {
temp[services_raw[n]] = services_raw[n + 1];
}
return temp;
}
console.log(getServices(response, lang));