JSFiddle - React, Tailwind, and code Playground
JavaScript
// "Simple" solution: use an array to hold the keys:
var aCities = [];
var sCity = "Vancouver";
aCities[sCity] = true;
// ... omit: more code to add more cities dynamically to the list...
alert(aCities.indexOf("Burnaby") >= 0); // Somewhat ugly, need to test numeric index instead of nice boolean.
// Now if we want to remove a value, we need to find the index, then use a splice() call, etc. and it gets very complicated.
////////////////////////////////////////////////////////////////////
// Instead, use an Object as a map to hold the keys:
var oCities = {};
var sCity = "Vancouver";
oCities[sCity] = true;
// ... omit: more code to add more cities dynamically to the list...
// Now we can easily test whether a particular city is in the list:
var bInList = oCities.hasOwnProperty(sCity);
alert(bInList);
// And we can easily remove an element from the list:
delete oCities[sCity];
var bInList = oCities.hasOwnProperty(sCity);
alert(bInList);