Q:

Create object property from variable contents

I have this simple object.
var myobj = {
   id: value
}

But instead of having a property named "id" I want the property identifier to be the value of:
$(this).attr('id');

I cannot preset this as I do not know the ID of the element. I want to be able to get my property value by
<id-of-element>.id

I understand I cannot do like this:
var myobj = {
   $(this).attr('id'): value
}

but how can I solve it? :)

A:

You can't assign a dynamic property name like that, but you can use the [] notation:
var myobj = {};
myobj[$(this).attr('id')] = value;

MDN Working with objects is a good resource covering this method.

