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. 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.

Sign up to request clarification or add additional context in comments.

1 Comment

that worked fine thanks. Sorry for the dumb question :)
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.