我想使用三元运算符在notEmpty上设置是或否,但是我的VSCode声纳标记用逗号用蓝色下划线标记:简化此表达式
代码:const notEmpty = list.lenght > 0 ? true : false;
const notEmpty = list.lenght > 0 ? true : false;
这实际上有效,但可能会更好。
尝试一下:
const notEmpty = list.length ? true : false;
无需将其与0进行比较,因为它为空时返回0,这是false,否则为true