1

I have an array : var list = ["",""];that will be filled with strings.

Before I let the user do something, I would like to make sure the array doesn't contain anymore empty entry.

I made a special function that I would like to work like that:

function checkEmptryEntry(array_name)
{
   if(arrayContainsEmptyEntry(array_name))
   {
      return "bad";
   }

   else
   {
      return "good";
   }
}

How could I do that ?

2

1 Answer 1

3

Assuming you have used jquery, you can use inArray:

return (!jQuery.inArray("", array_name) ? "good" : "bad");

Using native javascript, You can use indexOf to find first position of empty string. if it return -1, then array have no empty string:

return (array_name.indexOf("") == -1 ? "good" : "bad" ) ;
Sign up to request clarification or add additional context in comments.

1 Comment

This is exactly what I was looking for ! Thanks Milind !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.