In SQL we can see if a string is in a list like so:  Column IN ('a', 'b', 'c')   What's a good way to do this in JavaScript? It's so clunky to do this:  if (expression1 || expression2 || str === 'a' || str === 'b' || str === 'c') {    // do something }   And I'm not sure about the performance or clarity of this:  if (expression1 || expression2 || {a:1, b:1, c:1}[str]) {    // do something }   Or one could use the switch function:  var str = 'a',    flag = false;  switch (str) {    case 'a':    case 'b':    case 'c':       flag = true;    default: }  if (expression1 || expression2 || flag) {    // do something }   But that is a horrible mess. Any ideas?  In this case, I have to use Internet&nbsp;Explorer 7 as it's for a corporate intranet page. So ['a', 'b', 'c'].indexOf(str) !== -1 won't work natively without some syntax sugar.
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?
7172
What would be the best way to look in a string[] to see if it contains a element. This was my first shot at it. But perhaps there is something that I am overlooking. The array size will be no larger than 200 elements.  bool isStringInArray(string[] strArray, string key) {     for (int i = 0; i &lt;= strArray.Length - 1; i++)         if (strArray[i] == key)             return true;     return false; }
80715
In javascript, what is the best way to parse an INT from a string which starts with a letter (such as "test[123]")?  I need something that will work for the example below.  My JS:  $(document).ready(function() {      $(':input').change( function() {         id = parseInt($(this).attr("id"));  //fails for the data below         alert(id);     }); }   My generated HTML:  &lt;select id="attribute[123]"&gt; &lt;!-- various options --&gt; &lt;/select&gt; &lt;select id="attribute[456]"&gt; &lt;!-- various options --&gt; &lt;/select&gt;   Thank you!
10807
maybe there is a simple answer to my problem:  I have a mssql table ('Person') with a field for first and one for last name. I am coding a Program, where the User should be able to search for persons.     SELECT id, firstname, lastname FROM Person WHERE firstname LIKE   @searchstring + '%' OR lastname LIKE @searchstring + '%'   doesn't work very well, because if the user types 'John W' nothing is found.  For example the person I search for is called John Williams: It should work with searchstrings like 'John W', 'Williams Jo', 'Will' or 'Joh'  Concatenating first and lastname and use %Searchstring% also doesn't work well, because if the searchstring is e.g. 'Will' it should find people who are called Will, Willibald, Williams or Willson or something like that, but not a Person called Goodwill e.g.  And the query should be as fast as possible, because it is executed at every keydown...  edit: forgot to mention that the database must not be changed, because it is from another company.  Thank you for your help.
110974
I am just wondering if MariaDB or MySQL implements the &lt;table value constructor&gt; in the SQL Spec. In  and ?  SELECT * FROM ( VALUES (1) ) AS t(x);  x  ---  1 (1 row)   (syntax from ).
26779
Lets say I have an array like this:  string [] Filelist = ...   I want to create an Linq result where each entry has it's position in the array like this:  var list = from f in Filelist     select new { Index = (something), Filename = f};   Index to be 0 for the 1st item, 1 for the 2nd, etc.  What should I use for the expression Index= ?
1681
When using SQL, are there any benefits of using = in a WHERE clause instead of LIKE?  Without any special operators, LIKE and = are the same, right?
5927
I've been told not to use for...in with arrays in JavaScript. Why not?
42368
I have a python list, say l  l = [1,5,8]   I want to write a sql query to get the data for all the elements of the list, say  select name from students where id = |IN THE LIST l|   How do I accomplish this?
79438
Can anyone explain how the LIKE operator is implemented in current database systems (e.g. MySQL or Postgres)? or point me to some references that explain it?  The naive approach would be to inspect each record, executing a regular expression or partial string match on the field of interest, but I have a feeling (hope) that these systems do something smarter.
8231
Simple one really.  In SQL, if I want to search a text field for a couple of characters, I can do:  SELECT blah FROM blah WHERE blah LIKE '%text%'   The documentation for App Engine makes no mention of how to achieve this, but surely it's a common enough problem?
69159
How can you find the number of occurrences of a particular character in a string using sql?  Example: I want to find the number of times the letter ‘d’ appears in this string.  declare @string varchar(100) select @string = 'sfdasadhfasjfdlsajflsadsadsdadsa'
59026
Is there an AmpScript function that can be used in an equivalent manner to sql left, right and mid functions?   Thanks, Mark
66399
I have the following code:  const string Sql =      @"select distinct [name]        from tblCustomers        left outer join tblCustomerInfo on tblCustomers.Id = tblCustomerInfo.CustomerId         where (tblCustomer.Name LIKE '%@SEARCH%' OR tblCustomerInfo.Info LIKE '%@SEARCH%');";  using (var command = new SqlCommand(Sql, Connection)) {            command.Parameters.AddWithValue("@SEARCH", searchString);     ... }   This does not work, I tried this as well:  const string Sql =      @"select distinct [name]       from tblCustomers       left outer join tblCustomerInfo on tblCustomers.Id = tblCustomerInfo.CustomerId        where (tblCustomer.Name LIKE @SEARCH OR tblCustomerInfo.Info LIKE @SEARCH );";  using (var command = new SqlCommand(Sql, Connection)) {            command.Parameters.AddWithValue("@SEARCH", "'%" + searchString + "%'");     ... }   but this does not work as well. What is going wrong? Any suggestions?
2156
In Java is there a way to check the condition:  "Does this single character appear at all in string x"  without using a loop?
6087
I have seen this before in SQL and VB, I am now reverse engineering an Excel speadsheet and have come across the following formula:   =IF(D23&lt;&gt;0,"Insufficent",0)   I am converting it to ActionScript:    var result:String = [condition] ? 0 : "Insufficient";    but I am unsure of what D23 &lt;&gt; 0 means, is it simply "not equal"?
73427
How can i check if a list has certain string in salesforce. For example I have : anotherList which is from controller and has  this value [NAME_A, NAME_B, NAME_C]  Then in my page:      &lt;apex:repeat var="list" value="{!tesList}"&gt;         &lt;input type="checkbox" style="display:{!IF(CONTAINS(anotherList, list['name']), '','none')}" value="{!list['name']}" /&gt;     &lt;/apex:repeat&gt;   But i got an error saying that Error: Incorrect parameter type for function 'CONTAINS()'. Expected Text, received Object  So parameters should only be Strings right? But how can i do something like this in Visualforce page?  &lt;!-- JSTL sample --&gt;     &lt;c:forEach var="list" items="${testList}"&gt;             &lt;c:if test="${fn:contains(anotherList, list.name)}"&gt;                 &lt;input type="checkbox"  value="${list.name}" /&gt;             &lt;/c:if&gt;     &lt;/c:forEach&gt;