var data = [{
"name": "涡阳",
"pinyin": "WoYang"
}, {
"name": "邳州",
"pinyin": "PiZhou"
}, {
"name": "玉溪",
"pinyin": "YuXi"
}, {
"name": "无锡",
"pinyin": "WuXi"
}, {
"name": "萍乡",
"pinyin": "PingXiang"
}];
Catégorie selon les lettres A B C...liste
telles que
P->
{
"name": "萍乡",
"pinyin": "PingXiang"
},
{
"name": "邳州",
"pinyin": "PiZhou"
}
Description du lien similaire
Comment exploiter cet ensemble de données. .
我的代码,比较渣 求更优雅的写法
function jsfu(data) {
var obj={}
data.map(function(item, index) {
let codeIndex = item.pinyin.charAt(0)
if (!obj[codeIndex]) {
obj[codeIndex] = {
item: []
}
}
obj[codeIndex].item.push(item)
})
return obj
}