javascript - jQuery expression as object key -


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

Popular posts from this blog

javascript - How to name a jQuery function to make a browser's back button work? -

python - Django-easy-pdf: xhtml2pdf reporting reportlab 2.2+ is required, but 3.0 installed -

collision detection - C++ library for mesh to mesh intersection: what is available? -