I desided to make my code clearer by replacing
if (wrappedSet.length > 0)
to something like
if (wrappedSet.exists())
Is any native jq function for this? Or the only way is to extend it using $.fn.exists = ... ?
You could simply use
if (wrappedSet.length)
That will evaluate to TRUE if you have 1 or more elements and to FALSE if you have 0 elements
The function size does exactly this. On the other hand, why do you want to do this? The extra function call would reduce performance (albeit by an infinitesimally small amount) with no particular gain.
You could just do this:
if (wrappedSet.length) {
since 0 evaluates to false and any other number evaluates to true.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With