Use if and else to make judgments, but this code is really too redundant, please help optimize it

document.getElementsByClassName("current")[0].onclick = function () { //  1
            //alert("abv");
            for(var i = 0; i< listShow; iPP )
            {
                document.getElementsByClassName("sojob-item-main")[i].parentNode.style.display = "block";
                //console.log("title =", strObj[i]["title"]);
                document.getElementsByClassName("title")[i].innerHTML = "<a href="article_detail.html?id="+strObj[i]["id"]+"&userID="+strObj[i]["uid"]+"">"+strObj[i]["title"]+"</a>";
                
                if( strObj[i]["sex"] == "" ) {
                    document.getElementsByClassName("author")[i].innerHTML = strObj[i]["author"].substr(0,1) + "";
                } else if ( strObj[i]["sex"] == "" ) {
                    document.getElementsByClassName("author")[i].innerHTML = strObj[i]["author"].substr(0,1) + "";
                }
                
                var temptation = document.getElementsByClassName("temptation");
                if( strObj[i]["birthday"] == null ){
                    temptation[i].innerHTML = "";
                } else {
                    temptation[i].innerHTML = ":"+strObj[i]["birthday"].substr(0,4)+ "";
                }
                
                var publishTime = document.getElementsByClassName("publishTime");
                if( strObj[i]["dateline"] == null || strObj[i]["dateline"] == ""){
                    publishTime[i].innerHTML = "";
                } else {
                    publishTime[i].innerHTML = ":" + strObj[i]["dateline"];
                }
                            
                var fieldFinancing = document.getElementsByClassName("field-financing");
                if (strObj[i]["marriage"] == 1) {
                    fieldFinancing[i].innerHTML = "";
                } else if (strObj[i]["marriage"] == 2) {
                    fieldFinancing[i].innerHTML = "";
                } else if (strObj[i]["marriage"] == 3) {
                    fieldFinancing[i].innerHTML = "";
                } else if (strObj[i]["marriage"] == 4) {
                    fieldFinancing[i].innerHTML = "";
                } else if (strObj[i]["marriage"] == 5) {
                    fieldFinancing[i].innerHTML = "";
                } else if (strObj[i]["marriage"] == 6) {
                    fieldFinancing[i].innerHTML = "";
                } else if (strObj[i]["marriage"] == 7) {
                    fieldFinancing[i].innerHTML = "";
                } else if (strObj[i]["marriage"] == 8) {
                    fieldFinancing[i].innerHTML = "";
                } else if (strObj[i]["marriage"] == 9) {
                    fieldFinancing[i].innerHTML = "";
                } else if (strObj[i]["marriage"] == 10) {
                    fieldFinancing[i].innerHTML = "";
                } else {
                    fieldFinancing[i].innerHTML = ":";
                }
                
                var personEducation = document.getElementsByClassName("personEducation");
                if (strObj[i]["education"] == 0) {
                    personEducation[i].innerHTML == ":";
                } else if (strObj[i]["education"] == 1) {
                    personEducation[i].innerHTML = ":";
                } else if (strObj[i]["education"] == 2) {
                    personEducation[i].innerHTML = ":";
                } else if (strObj[i]["education"] == 3) {
                    personEducation[i].innerHTML = ":";
                } else if (strObj[i]["education"] == 4) {
                    personEducation[i].innerHTML = ":";
                } else if (strObj[i]["education"] == 5) {
                    personEducation[i].innerHTML = ":";
                } else if (strObj[i]["education"] == 6) {
                    personEducation[i].innerHTML = ":";
                } else {
                    personEducation[i].innerHTML = ":";
                }
                
                var personOccupation = document.getElementsByClassName("personOccupation");
                if( strObj[i]["occupation"] == null || strObj[i]["occupation"] == ""){
                    personOccupation[i].innerHTML = "";
                } else {
                    personOccupation[i].innerHTML = strObj[i]["occupation"];
                }
                
                var personSalary = document.getElementsByClassName("personSalary");
                personSalary[i].innerHTML = strObj[i]["salary"] + "/";
            }
        }

this is a piece of code I wrote, which uses a lot of if and esle, but I feel unable to optimize it myself

how can I optimize without es6?

May.08,2022

var mp = ['', '', '']
fieldFinancing[i].innerHTML = mp[strObj[i]['marriage']] || ':'

if else can be changed into switch


encapsulate options into arrays or objects


use the key-value pair of the object:


const actions = new Map([
  ['guest_1', ()=>{/*do sth*/}],
  ['guest_2', ()=>{/*do sth*/}],
  ['master_1', ()=>{/*do sth*/}],
  ['master_2', ()=>{/*do sth*/}],
  ['default', ()=>{/*do sth*/}],
])
const onButtonClick = (identity,status)=>{
  let action = actions.get(`${identity}_${status}`) || actions.get('default')
  action.call(this)
}
Menu