Saturday, 31 August 2013

Javascript setter and getter with key for object

Javascript setter and getter with key for object

I have an object in a variable var o={}; I want to do something like what
.push() method doing in array for my object.
JS code:
// Array:
var ar=[];
ar.push('omid');
ar.push('F');
var got=ar[1];
// above code is standard but not what I'm looking for !
/*-------------------------------------*/
// Object:
var obj={};
/* obj.push('key','value'); // I want do something like this
var got2=obj.getVal('key'); // And this
*/
I want to have result like this:
JS code:
obj={
key:'value'
}
Is this possible at all ?

No comments:

Post a Comment