I have a js object like:
obj = { name: \'js\', age: 20 };
now i want to access name field of obj, but i can only get string \'name\', s
It's quite simple, to access an object's value via a variable, you use square brackets:
var property = 'name'; var obj = {name: 'js'}; alert(obj[property]); // pops 'js'