简体   繁体   English

if语句简写,用于确定是否存在多个变量

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM