The object array makes a secondary judgment on the array according to the attribute value of the element.

        let tobj = [
            {a:"",b:2},
            {a:"joke",b:8},
            {a:"",b:23},
        
        ]
The

code is as above, and the decision condition is as follows: if the an of an element in tobj has a value, then query whether the an of other elements also has a value. As long as the value of an of an element is empty, event 1 is executed. If the an of all elements in the array has a value, or there is no value, then event 2 is executed.
the first condition is to cycle through all the elements to see if the an of any elements has a numerical value, and then make the next judgment and ask for advice.

Sep.08,2021

several ways for reference


21

//a2
//1
let [allEmpey,allExist] = tobj.reduce( (pre,cur)=>
    (cur.a ? [false,pre[1]] : [pre[0],false]) //a;a
    ,[true,true]) //true,true;
//true2
if(allEmpey||allExist) {
    console.log(2)
} else {
    console.log(1)
}
Menu