'objects' Tag

  • Feb
    09
    2010

    Setting a Nested Object with a String Key

    In one of the projects that I’m working on I had to setup a property of an object in a general way. In order to do so, i wrote the following function:

    function setValue(key,value,obj){
    obj[key.toString()] = value;
    }

    so calling the functuion like so

    var obj = { a:1,b:2,c:3 };
    setValue( "a" , 2 , obj );

    will [...]

 
Powered by Wordpress and MySQL. Theme by openark.org