If an array is empty, it looks like you can’t check it’s length using “.length”. What’s the best way to check if an array is empty?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can absolutely check an empty array’s length. However, if you try to do that on a null reference you’ll get an exception. I suspect that’s what you’re running into. You can cope with both though:
If that isn’t the cause, please give a short but complete program demonstrating the problem. If that was the cause, it’s worth taking a moment to make sure you understand null references vs “empty” collections/strings/whatever.