I know this code is correct, I did not write it. I am trying to understand what the code is doing.
- create variable
- loop through unordered list's children
- set cssClass = class name
- if the cssClass is not in myarray, add it to myarray
I am familiar with other ways to check to see if an item is in an array, and familiar with other ways to add an item to an array, but this method confuses me. Do other languages support this type of syntax?
var myarray = [];
$(".somelist > li").each(function() {
var cssClass = $(this).attr("class");
//This part below is CONFUSING
if(!myarray[cssClass]) {
myarray[cssClass] = true;
}
});
myarray = []should bemyarray = {}if any of the class names are non-integers.myarrayis an array instead of an object. Of course arrays are also objects, it's just not used as an array