Q:

Grab conditional values from Json, group unique ones

I'm pretty new to JS and stack community as well, I am having hard time grabbing values that fit the condition from my local json file. The original json is pretty large so These are the first two rows of my json;
[{
        "park_name": "Acadia National Park",
        "latitude": 44.35,
        "longitude": -68.21,
        "species_id": "ACAD-1000",
        "common_names": "Moose",
        "occurrence": "Present",
        "abundance": "Rare",
        "nativeness": "Native",
        "conservation_status": null,
        "location": "44.35, -68.21"
    },
    {
        "park_name": "Acadia National Park",
        "latitude": 44.35,
        "longitude": -68.21,
        "species_id": "ACAD-1001",
        "common_names": "Northern White-Tailed Deer, Virginia Deer, White-Tailed Deer",
        "occurrence": "Present",
        "abundance": "Abundant",
        "nativeness": "Native",
        "conservation_status": null,
        "location": "44.35, -68.21"
    }
]

I am trying to create a Leaflet Map using graded points. [The more species fit the condition, the larger the dots]. My first layer which is "MUST SEE PARKS" I wanna get species that are occurrence = "Present" and abundance = "Rare" (this exists in other rows that are not shown here) and put the dots on the map according to their location. There are many species that fit this condition in each park for example in "Acadia National Park" 141 species fit the condition so I need only one dot graded according to number of species that fit. I can get the species but can't grab the latitude and longitude for one park that contains 141 species, and for other parks it's the same, I have bunch of species but need only one [lat, lon]. This is my code to get conditions;
var visit = {};
var visit_loc = {};

for (var i = 0; i < metadata.length; i++) {
  var names = metadata[i].park_name;
  var abundance = metadata[i].abundance;
  var occurrence = metadata[i].occurrence;
  var locations = metadata[i].location;
  var latitude = metadata[i].latitude;
  var longitude = metadata[i].longitude;

  if (occurrence === "Present" && abundance === "Rare") {
    if (!visit[names] && !visit_loc[location]) {
      visit[names] = 1;
      visit_loc[location] = 1;
    } else {
      visit[names]++;
      visit_loc[location]++;
    }
  }
}

metadata here is my response from my local json. The output that I get from this formula is something like this:
Acadia National Park: 141
Arches National Park: NaN
Badlands National Park: NaN
Big Bend National Park: NaN
Biscayne National Park: NaN
...

and for visit_loc the output is this:
visit_loc
{http://localhost:8000/: 10768}
http://localhost:8000/: 10768
__proto__:
constructor: ƒ Object()
hasOwnProperty: ƒ hasOwnProperty()
isPrototypeOf: ƒ isPrototypeOf()
propertyIsEnumerable: ƒ propertyIsEnumerable()
toLocaleString: ƒ toLocaleString()
toString: ƒ toString()
valueOf: ƒ valueOf()
__defineGetter__: ƒ __defineGetter__()
__defineSetter__: ƒ __defineSetter__()
__lookupGetter__: ƒ __lookupGetter__()
__lookupSetter__: ƒ __lookupSetter__()
get __proto__: ƒ __proto__()
set __proto__: ƒ __proto__()

I have no clue what this means.
So here, the parks that come after the first one give me NaN but after I change my code to this:
if (occurrence === "Present" && abundance === "Rare") {
    if(!visit[names]){
        visit[names] = 1;                                  
    } else{
        visit[names]++;                                
    }

I get the output, the values for each park, output turns to this:
Acadia National Park: 141
Arches National Park: 132
Badlands National Park: 38
Big Bend National Park: 154
Biscayne National Park: 389

Which is good, I get the values I want but I can not get the latitude and longitude values for the parks fitting the criteria.
Sorry for keeping it so long and being complicated, this is the first question I ask here, does anybody have any idea about how to get latitude and longitude values for each park only once. Thank you.

A:

You need to increment visit and visit_loc independently. Your code only sets the elements to 1 when both are not yet set. If visit[names] is not set, but visit[locations] is set, the code assumes that both are already initialized and tries to increment them both. This fails for visit[names], so you get NaN there.
if (occurrence === "Present" && abundance === "Rare") {
    if(!visit[names]){
        visit[names] = 1;                                  
    } else{
        visit[names]++;                                
    }
    if (!visit_loc[locations]) {
        visit_loc[locations] = 1;
    } else {
        visit_loc[locations]++;
    }
}

