开发者

Replacing Object's key with dupliacte values during run time

var myNewKeyNames = ['asas','asas'];
var obj =[{key:'value',key:'value'}]
for(var i =0; i<obj.length; i++) {
     for(key in the obj[i]) {

          alert(key) // gives the keys in the object
          alert(myNewKeyNames) instead of key in the object which would rep the values
          alert(value) // gives the value in the object
    }
}

Now can i turn the key into some other values.... without using my loop's key value. I tried to replace... like this... but its not taking...

I don't want to rename the keys during the intial stage, just when the开发者_C百科 key is printed in the textboxxx at that time i want to name it different...


As I understood:

var myNewKeyNames = ['new_key1','new_key2'];
var obj =[ { key1: 'value1', key2: 'value2' } ];
for(var i = 0; i < obj.length; i++) { 
    var j = 0;
    for(key in obj[i]) {
        alert(myNewKeyNames[j++] + ': ' + obj[i][key]);
    }
}

Check it!


Don't quite understand what you want...but gave it a try. Check out the link below.

http://jsfiddle.net/qDgTm/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜