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 ?

B.T
  • 521
  • 1
  • 7
  • 26
  • 1
    Possible duplicate of [How do I check if an array includes an object in JavaScript?](https://stackoverflow.com/questions/237104/how-do-i-check-if-an-array-includes-an-object-in-javascript) – Drew Kennedy Jul 04 '17 at 14:18
  • What have you tried so far? Iterate through the array and check for at least one empty string, and please return a boolean. – Andrew Li Jul 04 '17 at 14:18

1 Answers1

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" ) ;
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125