I have a line of code that is supposed to act as a check for if the user inputs a value that isn't within my array.  I made an array with all valid inputs and then made and if statement that checks this.   var productCode = ["LT","ST","DC","LC","PR","SP"];  var productChosen = prompt("Choose a product code, LT, ST, DC, LC, PR, or SP");  if ( productChosen === productCode) {  etc.. }  else {  alert("Please input a valid product code"); }   It always goes to the else statement.
717
What is the most concise and efficient way to find out if a JavaScript array contains a value? This is the only way I know to do it: function contains(a, obj) {     for (var i = 0; i &lt; a.length; i++) {         if (a[i] === obj) {             return true;         }     }     return false; }  Is there a better and more concise way to accomplish this?
47989
Okay, we know that the following two lines are equivalent -    (0 == i) (i == 0)   Also, the first method was encouraged in the past because that would have allowed the compiler to give an error message if you accidentally used '=' instead of '=='.  My question is - in today's generation of pretty slick IDE's and intelligent compilers, do you still recommend the first method?    In particular, this question popped into my mind when I saw the following code -   if(DialogResult.OK == MessageBox.Show("Message")) ...    In my opinion, I would never recommend the above. Any second opinions?
76073
Help for a simple script  #!/bin/bash  array1=( prova1 prova2 slack64 )  a="slack64" b="ab"  if [ $a = $b ] then       echo "$a = $b : a is equal to b" else       echo "$a = $b: a is not equal to b" fi     This script simply doesn't work, I want a script which check if slack64 is present in a list(i use an array),and simply give me, yes is present,or no. I don't know how to compare an array with a single variable.
5927
I've been told not to use for...in with arrays in JavaScript. Why not?
116653
I have this:  If String.IsNullOrEmpty(editTransactionRow.pay_id.ToString()) = False Then     stTransactionPaymentID = editTransactionRow.pay_id 'Check for null value End If   Now, when editTransactionRow.pay_id is Null Visual Basic throws an exception. Is there something wrong with this code?
6421
I have two arrays in PHP as follows:  People:  Array (     [0] =&gt; 3     [1] =&gt; 20 )   Wanted Criminals:  Array (     [0] =&gt; 2     [1] =&gt; 4     [2] =&gt; 8     [3] =&gt; 11     [4] =&gt; 12     [5] =&gt; 13     [6] =&gt; 14     [7] =&gt; 15     [8] =&gt; 16     [9] =&gt; 17     [10] =&gt; 18     [11] =&gt; 19     [12] =&gt; 20 )   How do I check if any of the People elements are in the Wanted Criminals array?  In this example, it should return true because 20 is in Wanted Criminals.
37488
This works just fine:      protected void txtTest_Load(object sender, EventArgs e)     {         if (sender is TextBox) {...}      }   Is there a way to check if sender is NOT a TextBox, some kind of an equivalent of != for "is"?  Please, don't suggest moving the logic to ELSE{} :)
52980
I want to set a variable if my condition is true on my Ubuntu system.  This proves that my if-statement is correct:  $ (if [ 1 == 1 ]; then echo "hi there"; fi); hi there   This proves that I can set variables:  $ a=1 $ echo $a 1   This shows that setting a variable in the if-statement DOES NOT work:  $ (if [ 1 == 1 ]; then a=2; fi); $ echo $a 1   Any ideas why? All my  indicates that it should work like this...
11109
I've been having a lot of problems trying to figure out how to use scanf().  It seems to work fine with integers, being fairly straight forward scanf("%d", &amp;i).  Where I am running into issues is using scanf() in loops trying to read input.  For example:  do {   printf("counter: %d: ", counter);   scanf("%c %c%d", &amp;command, &amp;prefix, &amp;input); } while (command != 'q');    When I enter in a validly structured input like c P101, it seems to loop again before prompting me.  This seems to happen even with a single:  scanf("%c", &amp;c)    in a while loop.  It'll do the loop twice before prompting me again.  What is making it loop twice, and how do I stop it? When I enter in less amount of input that programmatically wouldn't have another character or number such as q, pressing enter seems to prompt me to enter more.  How do I get scanf() to process both single and double character entries?
98548
What is wrong with this code?  = IF (F3+E3+D3 &gt; 0, F3+E3+D3, 0)   I want the cell to contain the sum only if it is positive. If it is negative I want zero to be there.  Google Spreadsheet gives me error: Parse error.
88238
I have problem in some JavaScript that I am writing where the Switch statement does not seem to be working as expected.  switch (msg.ResultType) {   case 0:     $('#txtConsole').val("Some Val 0");     break;   case 1:     $('#txtConsole').val("Some Val 1");     break;   case 2:     $('#txtConsole').text("Some Val 2");     break; }   The ResultType is an integer value 0-2 and I can see that in FireBug.  In all cases, the switch transfers control to the final break statement which means all the logic is completely skipped.  What am I missing?
38112
Here's the scenario...    if (entry.Properties["something"].Value != null)   attribs.something = entry.Properties["something"].Value.ToString();   While effective and working correctly, this looks ugly to me.  If I don't check for a null before performing the ToString() then it throws an exception if the property was null.  Is there a better way to handle this scenario?  Much appreciated!
9353
I have a loop that is doing some error checking in my PHP code. Originally it looked something like this...  foreach($results as $result) {     if (!$condition) {         $halt = true;         ErrorHandler::addErrorToStack('Unexpected result.');     }      doSomething();  }  if (!$halt) {     // do what I want cos I know there was no error }   This works all well and good, but it is still looping through despite after one error it needn't. Is there a way to escape the loop?
27038
I have been using !$A.util.isEmpty(var) to check if value in empty/null/undefined in aura but this is not supported in LWC. What will be equivalent of this expression in LWC.   I don't want to write like if(this.var!==null &amp;&amp; this.var!==undefined &amp;&amp; this.var!=='')
83024
I have two arrays:  arrayA=(1 2 3) arrayB=(a b c)   and I want to print out one of them using a command line argument, i.e., without any if else.  I tried a few variations on the syntax with no success. I am wanting to do something like this:  ARG="$1"  echo ${array${ARG}[@]}   but I get a "bad substitution" error. How can I achieve this?
17861
How would I validate that a program exists, in a way that will either return an error and exit, or continue with the script?  It seems like it should be easy, but it's been stumping me.
56034
I doubt I am the only one who has come up with this solution, but if you have a better one please post it here. I simply want to leave this question here so I and others can search it later.   I needed to tell whether a valid date had been entered into a text box and this is the code that I came up with. I fire this when focus leaves the text box.  try {     DateTime.Parse(startDateTextBox.Text); } catch {     startDateTextBox.Text = DateTime.Today.ToShortDateString(); }