0

can convert a string into a property? I'm not very good with javascript objects, so I'd like your help ...

This is jsfiddle: http://jsfiddle.net/972fqz39/

var person = {    
  lastName : "Doe"   
};

var stringa= "lastName";
alert(person.stringa);

in this case it return undefined, i know that maybe i can to use person.lastName, but in my big code i can't use it.

So is possible to convert stringa in a property ??

Thanks!

Borja
  • 3,359
  • 7
  • 33
  • 66
  • 3
    `alert(person[stringa]);` – Jaromanda X Oct 31 '15 at 01:38
  • @JaromandaX WTF and that I continued to write person["stringa"] ! thanks a lot! if you write an ask i will check it – Borja Oct 31 '15 at 01:41
  • [Google](https://www.google.com/search?num=50&q=site%3Astackoverflow.com+javascript+variable+as+property&oq=site%3Astackoverflow.com+javascript+variable+as+property) –  Oct 31 '15 at 01:43

0 Answers0