javascript - jQuery expression as object key -
this question has answer here:
i need figure out how create dynamic key string object. expression makes javascript complain.
return {$(this).val(): true}; // returns object e.g. {2: true}
what doing wrong?
you have create object, use bracket notation dynamic key
var obj = {}; var val = $(this).val(); obj[val] = true; return obj;
or unnecessary one-liner
return (function(o,e) {o[e.value]=true; return o;})({}, this);
Comments
Post a Comment