1

I got the following lines of code:

 for (var i = 0; i<ke.length; i++)
        {

            var ar = ke[i];
            var temp = {ar :(n[a])}; //how to resolve a
            console.log(temp);

        }

temp an object which should contain a list of columnames(key) and values, but he takes a as literal, how can i fix that? n[a] is a json object and a the colum name

 current output: temp = {a:["some", "value"] }

what i want: {"valueOfA" : ["some", "value"] }

I am normally a java developer, so js seems so strange. I hope you can help me. Thanks in advance

1
  • You question is incomplete. Please add more details for others to understand. Thanks.
    – vivek_nk
    Commented Apr 2, 2014 at 8:09

2 Answers 2

1

Initialise temp to an empty object and then set its key value as below :

var temp = {};
temp[a] = // value to be stored

By doing so it will store the value contained in a as the key instead of storing a as a key.

1
  • that worked fine thanks. Sorry for the dumb question :)
    – malle
    Commented Apr 2, 2014 at 8:19
1

Look,

This is an empty javascript object:

var temp = {};

This is a javascript object with key a and value empty string:

var temp = {a:""};

if you want to get empty string (or whatever you put there, array, number etc.) you can get it like:

console.log(temp.a);

For your example, you can get the a value from there, or you can declare temp as:

var temp = (v[a]);

So, if you log temp, you will get the array from there.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.