简体   繁体   中英

How can I check if any of the values of the object properties are equal to 0?

如何检查对象属性的任何值是否等于0?

You will have to iterate over the object keys, and check the value of each one:

for(var p in x) {
    if(x[p] === 0) {
        console.log("Found!");
    }
}

Depending on whether you care about properties that may have been inherited from the prototype , you could add a hasOwnProperty check in there:

for(var p in x) {
    if(x.hasOwnProperty(p)) {
        if(x[p] === 0) {
            //Found it!
        }
    }
}

I program in ActionScript, which is a similar dialect, so I am almost sure it will be the same. Please try:

if(arr[0] != null)

Note that there is a difference between arr[0] and arr["0"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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