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)
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b31f4a-2bdf0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b31f4a-2bdf0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?