2015-11-08 86 views

回答

0

嘗試是這樣的:

var arr = [{id: 1, name: 'a'},{id: 2, name: 'b'},{id: 3, name: 'c'}]; 
var obj = {}; 

for (var i=0 ; i<arr.length ; ++i) { 
    obj[arr[i].id] = arr[i].name; 
} 

console.log(obj);