1

I am trying to form the following structure

{
    "details": [
        {
            "id": 1,
            "index": "index"
        },
        {
            "id": 2,
            "index": "index"
        }
    ],
    "user": "user"
}

For that iam trying

 var order = [];
 $('.movables').each(function(index, element){
    var id = $(this).children().attr('id');
    order.push({'id': id, 'index' : index});
 });
 order.push('user',user);

It gives wrong format. I dont know how to form that above structure.

I am getting id, index value from each method. It is working fine. Iam getting id, index & user values but i dont know how to form

1 Answer 1

6

Instead of an array, order should be an object, containing details property that is an array.

var order = {details: []};
$('.movables').each(function(index, element){
   var id = $(this).children().attr('id');
   order.details.push({'id': id, 'index' : index});
});
order.user = user;
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.