在实际工作中,若要判断list中是否存在,可采用以下办法:
let list = [{name:'tom',age:18},{name:'tom1',age:18},{name:'tom2',age:18}]
try {
list.forEach((item) => {
if (!item.name) {
throw new Error ("请检查名称")
} else if (!item.age) {
throw new Error ("请检查年龄")
}
})
} catch(e) {
this.$message.error(e)
}