Is this the best way to get the key and value from a JS object:
function jkey(p){for(var k in p){return k;}}
function jval(p){for(var k in p){return p[k];}}
var myobj = {'Name':'Jack'};
alert(jkey(myobj)+' equals '+jval(myobj));
Or is there a more direct or faster way ??
What I need to do is to me able to call the key-name and value seperately. the functions work and return the keyname and value, I just wondered if there was a smaller, faster, better way.
Here's a better example, I want to access the key:value as separate variables i.e {assistant:'XLH'}, key=assistant, val = 'XLH';
I only use this when I know for sure that it is a pair and only returns a single key and value.
formY={
    tab:[
        {
            tabID:'Main',
            fset:[
                    {
                        fsID:'Ec',
                        fields:[
                            {ec_id:'2011-03-002'},
                            {owner:'ECTEST'},
                            {assistant:'XLH'},
                            {ec_date:'14/03/2011'},
                            {ec_status:'Unreleased'},
                            {approval_person:'XYZ'},
                        ]
                    }
                ]
        }
        ]
}