[英]If statement shorthand for determining if multiple variables exist
Is there a shorthand for the following: 是否有以下简写:
if ((items.length > 0) && ($item.length > 0)) {
// Do Something...
}
Below is under the assumption that items
and $items
are arrays 下面假设
items
和$items
是数组
Just use items.length
which will be true for > 0
只需使用
items.length
,对于> 0
将为true
if (items.length && $items.length)
您可以删除> 0并使用truthy性质,因为0为false。
if (items.length && $item.length) {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.