我有一个场景来检查javscript中对象数组中的未定义字符串和空字符串。下面的代码部分工作,被卡住了。
在数组对象中,
如果字段值未定义或为空,则只有在newemp为false时才返回true。
如果字段值除国家外,其他字段未定义或为空,则只有在newemp为true时才返回true。
否则,当newemp为true且只有国家未定义时,如果newemp为false,且没有空或未定义的字段,则返回false。
function checkObjects(ob){
var result = ob.some(e=>e.country === true && (Object.keys(e)===undefined))
return result
}
var resultfor1 = checkObjects(obj1);
var resultfor2 = checkObjects(obj2);
var obj1=[
{id:1, newemp: true, country: undefined, cardno: 'S05', name: 'sam'},
{id:2, newemp: false, country: 'IN', cardno: 'S06', name: 'tomy'}
]
var obj2=[
{id:3, newemp: true, country: undefined, cardno: 'S05', name: 'ramson'},
{id:4, newemp: false, country: undefined, cardno: 'S06', name: ' '}
]
Expected output
// obj1
False
//obj2
True发布于 2022-02-24 14:35:50
在尝试使用对象时,这些对象不存在。您需要类似于"isLoading“之类的内容,当您的逻辑完成后,您可以尝试呈现
https://stackoverflow.com/questions/71250995
复制相似问题