How can i find matching element in array, for example  i want to find word in array element "Black" Array element is : ["Black footbal scarf"] So i understand how to match this by converting array to string, but how can i do it exactly with array elements  var color = "Black";  var arr = ["Black footbal scarf", "Blue footbal scar", "Red footbal scar"]; //Converting to string WORKS alert(arr.join("").indexOf(color));  alert(arr.indexOf(color));   So i need to get array index of the color from variable.
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?
37476
What is the easiest way to match non-ASCII characters in a regex? I would like to match all words individually in an input string, but the language may not be English, so I will need to match things like ü, ö, ß, and ñ. Also, this is in Javascript/jQuery, so any solution will need to apply to that.
4455
I have an array that is initialized like:  Element[] array = {new Element(1), new Element(2), new Element(3)};   I would like to convert this array into an object of the  class.  ArrayList&lt;Element&gt; arraylist = ???;
85935
I've got a multidimensional associative array which includes an elements like  $data["status"] $data["response"]["url"] $data["entry"]["0"]["text"]   I've got a strings like:  $string = 'data["status"]'; $string = 'data["response"]["url"]'; $string = 'data["entry"]["0"]["text"]';   How can I convert the strings into a variable to access the proper array element? This method will need to work across any array at any of the dimensions.
13955
Unless I am missing an obvious built-in method, what is the quickest way to get the nth occurrence of a string within a string?  I realize that I could loop the  method by updating its start index on each iteration of the loop. But doing it this way seems wasteful to me.
1085
Does the "for…in" loop in Javascript loop through the hashtables/elements in the order they are declared? Is there a browser which doesn't do it in order? The object I wish to use will be declared once and will never be modified.  Suppose I have:  var myObject = { A: "Hello", B: "World" };   And I further use them in:  for (var item in myObject) alert(item + " : " + myObject[item]);   Can I expect 'A : "Hello"' to always come before 'B : "World"' in most decent browsers?
110764
In the past and with most my current projects I tend to use a for loop like this:  var elements = document.getElementsByTagName('div'); for (var i=0; i&lt;elements.length; i++) {     doSomething(elements[i]); }   I've heard that using a "reverse while" loop is quicker but I have no real way to confirm this:  var elements = document.getElementsByTagName('div'),      length = elements.length;  while(length--) {     doSomething(elements[length]); }   What is considered as best practice when it comes to looping though elements in JavaScript, or any array for that matter?
32595
I need to set a constant value as true or false for the particular scenario not sure correct working or not const test = data.findIndex(d =&gt; d.Fname === '' &amp;&amp; d.Lname === '') &lt; 0 ? false : true;  if fname and Lname both are blank then i want to set test as false not sure what is happening here.
104870
I've been working on this task (see screenshot).     Here's my answer to it so far:  var sum_pairs=function(ints, s){   //your code here    var ptr_1 = 0,       ptr_2 = 0,       i = 0,       j = 0,       len = ints.length,       j_min = len,       arr_sum = [];    for (i; i &lt; len-1; i++){     for (j = i+1; j &lt; len; j++){       if(ints[i] + ints[j] === s){         if (j &lt; j_min){           j_min = j;           arr_sum = [parseInt(ints[i]), parseInt(ints[j])]         }       }     }   }  return ( (arr_sum.length === 0)? undefined : arr_sum );   }   However, while the tests all pass, it throws an STDERR about 'optimising the code':    How might I be able to optimise my code further?
1641
Is it possible to find the foreach index?  in a for loop as follows:  for ($i = 0; $i &lt; 10; ++$i) {    echo $i . ' '; }   $i will give you the index.  Do I have to use the for loop or is there some way to get the index in the foreach loop?
18448
Let's say I have an Array of numbers: [2,3,3,4,2,2,5,6,7,2]  What is the best way to find the minimum or maximum value in that Array?  Right now, to get the maximum, I am looping through the Array, and resetting a variable to the value if it is greater than the existing value:  var myArray:Array /* of Number */ = [2,3,3,4,2,2,5,6,7,2];  var maxValue:Number = 0;  for each (var num:Number in myArray) {     if (num &gt; maxValue)         maxValue = num; }   This just doesn't seem like the best performing way to do this (I try to avoid loops whenever possible).
70164
Lets say I have this array,  int[] numbers = {1, 3, 4, 9, 2};   How can I delete an element by "name"? , lets say number 4?  Even ArrayList didn't help to delete?  string strNumbers = " 1, 3, 4, 9, 2"; ArrayList numbers = new ArrayList(strNumbers.Split(new char[] { ',' })); numbers.RemoveAt(numbers.IndexOf(4)); foreach (var n in numbers) {     Response.Write(n); }
102926
Searching for " should return a list of questions that have the tag [comments] but not the tag [feature-request]. The right hand sidebar says that, but the search results are identical to .    As random points out, the operator works, but seems to be broken if a minus sign is the first tag in the resulting search URL. This is a problem because the system re-orders the tags when you put them into the search box, always putting the one with the minus sign first.    Edit: Here's another behaviour that I haven't encountered until now. I was trying to pattern search for tags that contain 'array' but NOT include '-array', so I did the search . The resulting page shows the right tags with the right operators on them, but the results aren't being filtered properly (the first result includes [multidimensional-array]). So I simplified and  (1,960 results), and then  (1,963 results -- what??), which still included that first question with [multidimensional-array] on it. Something is not working right here.
8442
I have a file (called "number.txt") which I want to read to an array in Java. How exactly do I go ahead and do this? It is a straight-forward "1-dimensional" file, containing 100 numbers.  The problem is that I get an exception every time. Apparently it can't find it (I am sure its spelled correctly). When looking through code examples, it doesn't specify the file's entire file path, only the name of the file itself. How would I go about doing that if its necessary?  Also, when reading the file, will the array automatically contain all the lines of the file, or will I have to make a loop which which copies every line to corresponding subscript i?  I've heard of BufferedReader class, what it's purpose, and how does it corelate to reading input?
12247
I have the following code:  List&lt;MobileElement&gt; messages = driver.findElements (By.id ("body_bubble")); //find all messages MobileElement lastMessage = messages.get (messages.size () - 1); //get last message  // xpath query to check if the message is delivered String xpathDeliveryStatus = ".//*[contains(@resource-id, 'delivered_indicator') or contains(@resource-id, 'read_indicator') or contains(@resource-id, 'sent_indicator')]";  MobileElement deliveryStatus = lastMessage.findElement (By.xpath (xpathDeliveryStatus));   I want to do the same except that I want to find the deliveryStatus variable using explicit wait.  So I want to find the deliveryStatus variable inside the lastMessage variable using  wait.until (ExpectedConditions.visibilityOfElementLocated (By.locator))   How can I do this?  I don't want to do it using one immense Xpath. Besides, I don't even know how to find the last element with the id body_bubble using Xpath, as the number of these elements is not fixed and always changing.  P.S. For example, in Python we can define WebDriverWait with an element in the constructor instead of driver:  WebDriverWait(webelement, self.timeout)  Unfortunately, it does not work in Java.
26241
I have the following string array:  var sa = new string[] {"yabba","dabba","doo"};   I can convert it to "yabba, dabba, doo" it using string.Join() but what is the super-cool LINQ way of doing it?  The Join extension method seems promising but for a novice like me very confusing.
119008
Given this string:  SET @text = "&lt;a href=""https://salesforce.stackexchange.com""target=""_blank""&gt;Salesforce&lt;/a&gt; &lt;a href=""https://stackoverflow.com"" target=""_blank""&gt;Everything else&lt;/a&gt;"   And this function:  SET @matching = '\s+(?:[^&gt;]*?\s+)?href="([^"]*)"' SET @output = RegExMatch(@text, @matching, 1)   How can I manage to find and print an arbitrary number of matches in my string? E.g. in above example, I would like to present e.g. a rowset with each URL in each row.