循环遍历获取A-Z数组
String.fromCharCode(65) === 'A';
String.fromCharCode(90) === 'Z';
let letterArr = []; for(let i = 65; i< 91; i++) { letterArr.push(String.fromCharCode(i)) };
letterArr结果值:["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
let dataList = [ {name: '北京', pinyin: 'beijing'}, {name: '郑州', pinyin: 'zhengzhou'}, {name: '武汉', pinyin: 'wuhan'}, ]; let newDataList = []; for(let j=0; j< letterArr.length; j++){ let arr = dataList.filter(item => item.pinyin.substring(0,1)===letterArr[j].toLowerCase()); if(arr.length > 0) { newDataList.push({ index: letterArr[j], list: arr }) } }

浙公网安备 33010602011771号