输入sr=[{name:1,sex:'wem'},{name:2,sex:'wyy'},...];
输出 sr=[A:{1,wem'},B:{2,'wyy'},C...];
代码如下
var sr=[{name:1,sex:'wem'},{name:2,sex:'wyy'}];
var br=[];
for(var i=0;i<sr.length;i++){
br[i]=[];
for(var key in sr[i]){
br[i].push(sr[i][key]);
}
}
var arr=[];
var result=[];
for(var i=0;i<br.length;i++)
{
arr.push(String.fromCharCode((65+i))); //依次传入A-Z的25个字母
result[arr[i]]=br[i];
}
console.log(result)
输出