(This is a follow up question from Empty set in javascript)
I have a set in javascript defined like this:
function createSetFromList(list) {
var set = { };
for (var i = 0; i < list.length; i++)
set[list[i]] = true;
return set;
}
I initialize one set like this:
myset = createSetFromList(["apple", "orange", "banana"]);
Now I would like to see the properties of that set. I try with this:
function showProperties(v) {
for (x in v) {
if (v.hasOwnProperty(x)) {
$.log(x + " belongs");
} else {
$.log(x + " does not belong");
}
}
}
I now try to see the defined properties:
showProperties(myset);
The only output I get, no matter how I initialize the array, is:
undefined belongs
What is going on? How can I walk the set elements?