DEV Community

Discussion on: 1 line of code: How to check if an Array is empty

Collapse
 
martinkr profile image
Martin Krause

Thank you for your extensive contribution.

I can understand you comments and see where ou are coming from. Let me explain why I use this code.

I was using the version you posted for some time but ran into the problem that it returns false if the argument is not an array. This lead to problems in the code relying on the return value.

I'm deliberately not throwing the error,so it's not necessary to wrap it in an try ... catch - you can decide how to handle the error by yourself.

Cheers!

Some comments have been hidden by the post's author - find out more