How to dynamic call property on javascript object with jQuery

Posted by Massimo Ugues on Stack Overflow See other posts from Stack Overflow or by Massimo Ugues
Published on 2010-04-01T08:46:34Z Indexed on 2010/04/01 8:53 UTC
Read the original article Hit count: 392

Filed under:
|

Hallo all. I got a javascript object with some propeties let's say

function Animal() {
this.id;
this.name;

I need to call id function in a dynamic way to get and set its value: something like this

Animal animal = new Animal();
var propertyName = "id";
animal.+propertyName = "name";

Is there an elegant way to do it? With jQuery?

Kind regards

Massimo

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript