I have an array of numbers. The array may contain a zero.
How can I check if the array contains a number or not? I am currently doing that:
if (Number(arr. value(pos)) != false)
This however, considers 0 as false too. So if a 0 is in the array, it will consider it as if the array was empty.
How can I overcome this?
Try this:
if (Number(arr. value(pos)) !== false)!=does a “falsy” check.0, undefined, false, null, '',andNaNare all falsy. Everything else is “truthy”. If you want to test for false only (and not all other falsy statements) you have to use===or!==. Try to avoid!=and==, because most if the time you actually mean!==and===