Creating objects from array to json object

Far*_*uja 0 javascript jquery

I have an array of object like this

[
    {"id": "1", "name": "test"},
    {"id": "2", "name": "test2"},
    {"id": "3", "name": "test3"}
]
Run Code Online (Sandbox Code Playgroud)

I want to convert it to object list this

{
  "1": {"name": "test"},
  "2": {"name": "test2"},
  "3": {"name": "test3"},
}
Run Code Online (Sandbox Code Playgroud)

Den*_*ret 6

You may use reduce :

var obj = arr.reduce(function(m,o){ m[o.id]={name:o.name}; return m }, {});
Run Code Online (Sandbox Code Playgroud)

Side note : please be sure to read and try to understand T.J.'s comment about JSON