0
var data = [];
var id = 23;
var num = 12;
var dog_trialset = 15;
var cat_trialset = 23;

problem from here

data.push({id:{num:num, dog_trialset:dog_trialset, cat_trialset:cat_trialset}});

ajax post to php

[data] => Array
    (
        [0] => Array
            (
                [id] => Array
                    (
                        [num] => 12
                        [dog_trialset] => 15
                        [cat_trialset] => 34
                    )

            )

    )

I want [id] => Array(...) to [23] => Array(...);

Thanks

2
  • 5
    i dont understand your question. Commented Nov 26, 2010 at 9:48
  • @Srinivas Reddy Thatiparthy: The OP is using the identifier id in the literal object, but expected to use the value of the variable id as identifier. Commented Nov 26, 2010 at 10:13

1 Answer 1

0

You can use a variable as the key using the subscript operator:

var row = {};
row[id] = {num:num,dog_trialset:dog_trialset,cat_trialset:cat_trialset};
data.push(row);
Sign up to request clarification or add additional context in comments.

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.