I am relatively new to JS and would like to find the best method to set one variable equal to a subset of another variable another based on a dynamic condition.
In the example below,
clickedCodeis a string that changes after each click event (all of the code below is within a click.event function).featuresis an array of features with 400 elements, each containing apropertiesobject which in turn contains elements such as latitude, longitude, etc.citiesis an empty arrayvar clickedCode // dynamically changing string var cities = []; var features = map.queryRenderedFeatures({layers:['uni']});
for example, if I log some properties of the first feature, I will see:
var lon = features[0].properties.lon
var lat = features[0].properties.lat
var code = features[0].properties.code
console.log("" + lon + " " + lat + " " + code);
4.7005 50.8798 EMPHID
My objective is to subset features where features[i].properties.code is equal to clickedCode and then set cities equal to the resulting array so that roughly :
cities = features where features[i].properties.code === clickedCode
Any advice and explanation of structuring this in javascript would be helpful