SOURCE


//我是输入,替换 = 后面的就行
var str = [{ "company": "兰考县仪封镇", "classes": "正部级" }, { "company": "兰考县仪封镇", "classes": "正厅级" }, { "company": "兰考县仪封镇", "classes": "正厅级" }, { "company": "兰考县仪封镇", "classes": "副厅级" }, { "company": "兰考县仪封镇", "classes": "副厅级" }, { "company": "兰考县仪封镇", "classes": "省处级" }, { "company": "兰考县许河乡", "classes": "省处级" }, { "company": "兰考县许河乡", "classes": "省处级" }, { "company": "兰考县许河乡", "classes": "省处级" }, { "company": "兰考县许河乡", "classes": "省处级" }, { "company": "兰考县孟寨乡", "classes": "副厅级" }, { "company": "兰考县孟寨乡", "classes": "省处级" }, { "company": "兰考县三义寨乡", "classes": "正部级" }, { "company": "兰考县三义寨乡", "classes": "副部级" }, { "company": "兰考县三义寨乡", "classes": "副部级" }, { "company": "兰考县三义寨乡", "classes": "正厅级" }, { "company": "兰考县三义寨乡", "classes": "正厅级" }, { "company": "兰考县三义寨乡", "classes": "副厅级" }, { "company": "兰考县三义寨乡", "classes": "副厅级" }, { "company": "兰考县三义寨乡", "classes": "副厅级" }, { "company": "兰考县三义寨乡", "classes": "省处级" }, { "company": "兰考县三义寨乡", "classes": "省处级" }, { "company": "兰考县三义寨乡", "classes": "省处级" }, { "company": "兰考县三义寨乡", "classes": "省处级" }, { "company": "兰考县三义寨乡", "classes": "省处级" }, { "company": "兰考县葡萄架乡", "classes": "正部级" }, { "company": "兰考县葡萄架乡", "classes": "正厅级" }, { "company": "兰考县葡萄架乡", "classes": "副厅级" }, { "company": "兰考县葡萄架乡", "classes": "市副厅级" }, { "company": "兰考县葡萄架乡", "classes": "省处级" }, { "company": "兰考县堌阳镇", "classes": "正部级" }, { "company": "兰考县堌阳镇", "classes": "副部级" }, { "company": "兰考县堌阳镇", "classes": "正厅级" }, { "company": "兰考县堌阳镇", "classes": "正厅级" }, { "company": "兰考县堌阳镇", "classes": "副厅级" }, { "company": "兰考县堌阳镇", "classes": "副厅级" }, { "company": "兰考县堌阳镇", "classes": "副厅级" }, { "company": "兰考县堌阳镇", "classes": "市正厅级" }, { "company": "兰考县堌阳镇", "classes": "市副厅级" }, { "company": "兰考县堌阳镇", "classes": "省处级" }, { "company": "兰考县堌阳镇", "classes": "省处级" }, { "company": "兰考县考城镇", "classes": "正厅级" }, { "company": "兰考县红庙镇", "classes": "正部级" }, { "company": "兰考县红庙镇", "classes": "副部级" }, { "company": "兰考县红庙镇", "classes": "副部级" }, { "company": "兰考县红庙镇", "classes": "正厅级" }, { "company": "兰考县红庙镇", "classes": "市正厅级" }, { "company": "兰考县红庙镇", "classes": "市副厅级" }, { "company": "兰考县谷营镇", "classes": "副国级" }, { "company": "兰考县谷营镇", "classes": "正部级" }, { "company": "兰考县谷营镇", "classes": "副厅级" }, { "company": "兰考县谷营镇", "classes": "省处级" }, { "company": "兰考县小宋镇", "classes": "正部级" }, { "company": "兰考县小宋镇", "classes": "副厅级" }, { "company": "兰考县小宋镇", "classes": "市副厅级" }, { "company": "兰考县小宋镇", "classes": "市副厅级" }, { "company": "兰考县小宋镇", "classes": "省处级" }, { "company": "兰考县东坝头镇", "classes": "副国级" }, { "company": "兰考县东坝头镇", "classes": "正部级" }, { "company": "兰考县东坝头镇", "classes": "副部级" }, { "company": "兰考县东坝头镇", "classes": "副部级" }, { "company": "兰考县东坝头镇", "classes": "正厅级" }, { "company": "兰考县东坝头镇", "classes": "副厅级" }, { "company": "兰考县东坝头镇", "classes": "副厅级" }, { "company": "兰考县东坝头镇", "classes": "副厅级" }, { "company": "兰考县东坝头镇", "classes": "副厅级" }, { "company": "兰考县东坝头镇", "classes": "副厅级" }, { "company": "兰考县东坝头镇", "classes": "副厅级" }, { "company": "兰考县东坝头镇", "classes": "省处级" }, { "company": "兰考县东坝头镇", "classes": "省处级" }, { "company": "兰考县东坝头镇", "classes": "省处级" }, { "company": "兰考县兰阳街道", "classes": "副国级" }, { "company": "兰考县兰阳街道", "classes": "市副厅级" }, { "company": "兰考县兰阳街道", "classes": "市副厅级" }, { "company": "兰考县桐乡街道", "classes": "副部级" }, { "company": "兰考县桐乡街道", "classes": "副部级" }, { "company": "兰考县桐乡街道", "classes": "副部级" }, { "company": "兰考县桐乡街道", "classes": "副部级" }, { "company": "兰考县桐乡街道", "classes": "正厅级" }, { "company": "兰考县桐乡街道", "classes": "正厅级" }, { "company": "兰考县桐乡街道", "classes": "副厅级" }, { "company": "兰考县桐乡街道", "classes": "副厅级" }, { "company": "兰考县桐乡街道", "classes": "副厅级" }, { "company": "兰考县桐乡街道", "classes": "副厅级" }, { "company": "兰考县桐乡街道", "classes": "市副厅级" }, { "company": "兰考县桐乡街道", "classes": "市副厅级" }, { "company": "兰考县桐乡街道", "classes": "省处级" }, { "company": "兰考县桐乡街道", "classes": "省处级" }, { "company": "兰考县桐乡街道", "classes": "省处级" }, { "company": "兰考县桐乡街道", "classes": "省处级" }, { "company": "兰考县桐乡街道", "classes": "省处级" }, { "company": "兰考县桐乡街道", "classes": "省处级" }, { "company": "兰考县桐乡街道", "classes": "省处级" }, { "company": "兰考县桐乡街道", "classes": "省处级" }, { "company": "兰考县桐乡街道", "classes": "省处级" }, { "company": "兰考县桐乡街道", "classes": "省处级" }, { "company": "兰考县桐乡街道", "classes": "省处级" }, { "company": "兰考县桐乡街道", "classes": "省处级" }, { "company": "兰考县惠安街道", "classes": "正部级" }, { "company": "兰考县惠安街道", "classes": "正厅级" }, { "company": "兰考县惠安街道", "classes": "正厅级" }, { "company": "兰考县惠安街道", "classes": "副厅级" }, { "company": "兰考县惠安街道", "classes": "副厅级" }, { "company": "兰考县惠安街道", "classes": "副厅级" }, { "company": "兰考县惠安街道", "classes": "市副厅级" }, { "company": "兰考县惠安街道", "classes": "省处级" }, { "company": "兰考县惠安街道", "classes": "省处级" }, { "company": "兰考县惠安街道", "classes": "省处级" }]

var AREA_MONEY = 3
ResultData = function (id, company, zcountryTime, fcountryTime, zprovicetime,
    fprovicetime, ztingTime, ftingTime, zcitytime, fcitytime, zareatime
) {
    this.id = id;
    this.company = company;
    this.zcountryTime = zcountryTime;
    this.zprovicetime = zprovicetime;
    this.ztingTime = ztingTime;
    this.zcitytime = zcitytime;
    this.zareatime = zareatime;
    this.fcountryTime = fcountryTime;
    this.fprovicetime = fprovicetime;
    this.ftingTime = ftingTime;
    this.fcitytime = fcitytime;
}

var resultDatas = new Array;
var admirDatas = str;
var itemId = 0, zcountryTime = 0, zprovicetime = 0, ztingTime = 0,
    zcitytime = 0, zareatime = 0, fcountryTime = 0, fprovicetime = 0, ftingTime = 0,
    fcitytime = 0;
for (var i = 0; i < admirDatas.length; i++) {
    if (i == 0) {
        itemId++;
        if (admirDatas[i].classes == "正国级") {
            zcountryTime++;
        } else if (admirDatas[i].classes == "正部级") {
            zprovicetime++;
        } else if (admirDatas[i].classes == "正厅级") {
            ztingTime++;
        } else if (admirDatas[i].classes == "市正厅级") {
            zcitytime++;
        } else if (admirDatas[i].classes == "省处级") {
            zareatime++;
        } else if (admirDatas[i].classes == "副国级") {
            fcountryTime++;
        } else if (admirDatas[i].classes == "副部级") {
            fprovicetime++;
        } else if (admirDatas[i].classes == "副厅级") {
            ftingTime++;
        } else if (admirDatas[i].classes == "市副厅级") {
            fcitytime++;
        }
        var resultdata = {
            id: itemId,
            company: admirDatas[i].company,
            zcountryTime: zcountryTime,
            fcountryTime: fcountryTime,
            zprovicetime: zprovicetime,
            fprovicetime: fprovicetime,
            ztingTime: ztingTime,
            ftingTime: ftingTime,
            zcitytime: zcitytime,
            fcitytime: fcitytime,
            zareatime: zareatime




        };
        resultDatas.push(resultdata)

        zcountryTime = 0
        zprovicetime = 0
        ztingTime = 0
        zcitytime = 0
        zareatime = 0
        fcountryTime = 0
        fprovicetime = 0
        ftingTime = 0
        fcitytime = 0
    }
    if (i > 0) {
        if (admirDatas[i].company == admirDatas[i - 1].company) {
            if (admirDatas[i].classes == "正国级") {
                resultDatas[resultDatas.length - 1].zcountryTime++;
            } else if (admirDatas[i].classes == "正部级") {
                resultDatas[resultDatas.length - 1].zprovicetime++;
            } else if (admirDatas[i].classes == "正厅级") {
                resultDatas[resultDatas.length - 1].ztingTime++;
            } else if (admirDatas[i].classes == "省处级") {
                resultDatas[resultDatas.length - 1].zareatime++;
            } else if (admirDatas[i].classes == "正市厅级") {
                resultDatas[resultDatas.length - 1].zcitytime++;
            } else if (admirDatas[i].classes == "副国级") {
                resultDatas[resultDatas.length - 1].fcountryTime++;
            } else if (admirDatas[i].classes == "副部级") {
                resultDatas[resultDatas.length - 1].fprovicetime++;
            } else if (admirDatas[i].classes == "副厅级") {
                resultDatas[resultDatas.length - 1].ftingTime++;
            } else if (admirDatas[i].classes == "副市厅级") {
                resultDatas[resultDatas.length - 1].fcitytime++;
            }
        } else {
            itemId++;
            if (admirDatas[i].classes == "正国级") {
                zcountryTime++;
            } else if (admirDatas[i].classes == "正部级") {
                zprovicetime++;
            } else if (admirDatas[i].classes == "正厅级") {
                ztingTime++;
            } else if (admirDatas[i].classes == "市正厅级") {
                zcitytime++;
            } else if (admirDatas[i].classes == "省处级") {
                zareatime++;
            } else if (admirDatas[i].classes == "副国级") {
                fcountryTime++;
            } else if (admirDatas[i].classes == "副部级") {
                fprovicetime++;
            } else if (admirDatas[i].classes == "副厅级") {
                ftingTime++;
            } else if (admirDatas[i].classes == "市副厅级") {
                fcitytime++;
            }
            var resultdata = {
                id: itemId,
                company: admirDatas[i].company,
                zcountryTime: zcountryTime,
                fcountryTime: fcountryTime,
                zprovicetime: zprovicetime,
                fprovicetime: fprovicetime,
                ztingTime: ztingTime,
                ftingTime: ftingTime,
                zcitytime: zcitytime,
                fcitytime: fcitytime,
                zareatime: zareatime
            };
            resultDatas.push(resultdata)

            zcountryTime = 0
            zprovicetime = 0
            ztingTime = 0
            zcitytime = 0
            zareatime = 0
            fcountryTime = 0
            fprovicetime = 0
            ftingTime = 0
            fcitytime = 0
        }
    }
}


document.write(
    JSON.stringify(resultDatas))
console 命令行工具 X clear

                    
>
console