-1

How to do ElementName get value from ElementId?

var Elements = {
    ElementId: '#myelement',
    ElementName: Elements.ElementId
};

alert(Elements.ElementName);
  • The object doesn't exist while it's being defined. So assign that property after you've created the first, or use a constructor function if this is suitable to represent some commonly defined object. –  Aug 02 '16 at 20:46

1 Answers1

-1

You haven't created the object yet, so it's not going to be defined. You can define that property on the object once it's created like this:

var Elements = {
  ElementId: '#myelement'
};

Elements['ElementName'] = Elements.ElementId;

alert(Elements.ElementName);

However I think there's a better way; what specifically are you using the name and id properties for?

Taylor Daughtry
  • 249
  • 1
  • 9