Ad

If Condition With NOT Operator In Javascript

- 1 answer

I have the following code:

   for (i = 0; i < words.length; i++) 
   {
        if (words[i].match(' '))
            words2[words2.length] = words[i];
    }

I want my if statement to be executed like this:

     if !(words[i].match(' '))
        words2[words2.length] = words[i];

How can I make the following statement if not, instead of regular if?

Ad

Answer

the complete answer:

var words2 = [];

for (i = 0; i < words.length; i++) 
{
    if (!words[i].match(' '))
        words2.push(words[i]);
 }
Ad
source: stackoverflow.com
Ad