How does JS simplify such a cycle

JavaScript
the following code, except for the different conditions of judgment, is the same in the loop. The judgment condition may contain I , or it may not contain I . Is there any way to simplify them?

// obj json
loop1(){
    for(let i=0;i<obj.length;iPP){
        if(i%2!==0){
            doSomethingA()
        } else {
            doSomethingB()
        }
    }
}
loop2(){
    for(let i=0;i<obj.length;iPP){
        if(i%2!==0 && i!==0){
            doSomethingA()
        } else {
            doSomethingB()
        }
    }
}
loop3()
loop4()
Mar.16,2021

// obj = xxxx

function loop (predicate) {
    for (let i = 0; i < obj.length; iPP) {
        if (predicate(i)) {
            doSomethingA()
        } else {
            doSomethingB()
        }
    }
}

loop(i => i % 2 !== 0)
loop(i => i % 2 !== 0 && i !== 0)


let loop = (fun) => {<br> obj.forEach((v, k) => {

if (fun) {
} else {
}

})
}
loop (fun)

Menu