在javascript中形成数组值

Moh*_*ail 1 javascript arrays jquery

我想形成以下结构

{
    "details": [
        {
            "id": 1,
            "index": "index"
        },
        {
            "id": 2,
            "index": "index"
        }
    ],
    "user": "user"
}
Run Code Online (Sandbox Code Playgroud)

为了那个iam尝试

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

它给出了错误的格式.我不知道如何形成上述结构.

我得到id,每个方法的索引值.它工作正常.我得到id,索引和用户值,但我不知道如何形成

Ion*_*zău 6

而不是数组,order应该是一个对象,包含details一个数组属性.

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