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

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

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