What I'm trying to achieve:
Create an array for each country 'item_location' and push object values with 'item_location' as the key.
e.g
[{USA:1},{USA:2}], [{UK:1},{UK:2}], [{CUBA:1},{CUBA:2}]
or
e.g
[
{
USA: {"Activity/Adventure": 1, "Beach Escape": 2},
UK: {"Activity/Adventure": 1, "Beach Escape": 2},
CUBA: {"Activity/Adventure": 1, "Beach Escape": 2}
}
]
Current Problems:
The object key says 'item_location' instead of picking up the 'item_location' var value 'item.Location'.
var filter = [];
for(var ix = 0; ix < jsonData.length; ix++)
{
var item = jsonData[ix];
var item_location = item.Location;
var item_ = [{item_location:item["Activity/Adventure"]},{item_location:item["Beach Escape"]}];
filter.push({item_});
}
console.log(filter);
ANWSER:
function filterData(){
var filter = [];
for(var ix = 0; ix < jsonData.length; ix++)
{
var item = jsonData[ix];
var item_location = item.Location;
var item1 = {}, item2= {};
item1[item_location] = item["Activity/ Adventure"];
item2[item_location] = item["Beach Escape"];
var item_ = [item1, item2];
filter.push(item_);
}
console.log(filter);
}