In the following code why is i treated as a string? I have to multiple it by 1 to get it to convert back to a number.    getPositionInArray(value, array) {     console.log('array = ', array);      let i = 0; // why is i a string?     for (i in array) {       if (array[i].toLowerCase() === value) {         let positionOnUI = i * 1 + 1; // why can't I use i + 1?         return positionOnUI;       }     }     return null;   }
5927
I've been told not to use for...in with arrays in JavaScript. Why not?
80355
I have this struct:  struct Map {     public int Size;      public Map ( int size )     {         this.Size = size;     }      public override string ToString ( )     {         return String.Format ( "Size: {0}", this.Size );     } }   When using array, it works:  Map [ ] arr = new Map [ 4 ] {     new Map(10),     new Map(20),     new Map(30),     new Map(40)};  arr [ 2 ].Size = 0;   But when using List, it doesn't compile:  List&lt;Map&gt; list = new List&lt;Map&gt; ( ) {     new Map(10),     new Map(20),     new Map(30),     new Map(40)};  list [ 2 ].Size = 0;   Why?
106126
I was debugging something and discovered some strangeness in JavaScript:  alert(1=='') ==&gt; false alert(0=='') ==&gt; true alert(-1=='') ==&gt; false   It would make sense that an implied string comparison that 0 should = '0'. This is true for all non-zero values, but why not for zero?
109364
I have a method which takes params object[] such as:  void Foo(params object[] items) {     Console.WriteLine(items[0]); }   When I pass two object arrays to this method, it works fine:  Foo(new object[]{ (object)"1", (object)"2" }, new object[]{ (object)"3", (object)"4" } ); // Output: System.Object[]   But when I pass a single object[], it does not take my object[] as the first param, instead it takes its all elements like I wanted to pass them one by one:  Foo(new object[]{ (object)"1", (object)"2" }); // Output: 1, expected: System.Object[]   How do I pass a single object[] as a first argument to a params array?
43371
PHP has the habit of evaluating (int)0 and (string)"0" as empty when using the empty() function. This can have unintended results if you expect numerical or string values of 0. How can I "fix" it to only return true to empty objects, arrays, strings, etc?
109558
Are these two equivalent?  char * aString = "This is a string.";  char aString[] = "This is a string.";  From my understanding, C++ stores strings by their addresses, so the pointer is getting a valid address. I assume the strings are also stored as type char? But how does it know how much memory to allocate for the string? Normally, char arrays need their array size preset. I believe the [] type arrays are counted by the compiler before compilation. Is this what happens for the string literal pointer as well?  On to my second question, what is the difference between these two:  int someNumber;  int * someNumber = new int;  The second is supposed to be dynamic allocation. If I understand the concept right, it allocates the memory as soon as it reads the declaration. But what happens in the standard declaration? Basically, I need to understand how dynamic allocation is advantageous over standard declarations.
26027
How do I append an object (such as a string or number) to an array in JavaScript?
6195
Using PHP, what's the fastest way to convert a string like this: "123" to an integer?  Why is that particular method the fastest? What happens if it gets unexpected input, such as "hello" or an array?
588
JavaScript allows functions to be treated as objects--if you first define a variable as a function, you can subsequently add properties to that function.  How do you do the reverse, and add a function to an "object"?  This works:  var foo = function() { return 1; }; foo.baz = "qqqq";   At this point, foo() calls the function, and foo.baz has the value "qqqq".  However, if you do the property assignment part first, how do you subsequently assign a function to the variable?  var bar = { baz: "qqqq" };   What can I do now to arrange for bar.baz to have the value "qqqq" and bar() to call the function?
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= ?
54515
I want to implement numbering scheme like Microsoft Word uses for numbering.  first one gets = A,next is  B, next is C, .... then AA, then AB,....and so on.  as shown below   A        B  C  .   .  AA  AB  AC  .  .  AAA  AAB  ....   '=>' here means converted to.  some examples:       1 =&gt; A 26 =&gt; Z 27 =&gt; AA 52 =&gt; AZ 53 =&gt; BA   and heres the code for it:     var convertToNumberingScheme = function(n){         var x = n-1,             r26 = x.toString(26),             baseCharCode = "A".charCodeAt(0);          var arr = r26.split(''),             len = arr.length;          var newArr =arr.map(function(val,i){             val = parseInt(val,26);              if( (i === 0) &amp;&amp; ( len &gt; 1)){                 val = val-1;             }              return String.fromCharCode(baseCharCode + val);         });         return newArr.join('');     }   It seems to work fine, but any ideas if there are some potential bugs or ways to  optimize this.
98955
Suppose I have this code: var myArray = new Object(); myArray[&quot;firstname&quot;] = &quot;Bob&quot;; myArray[&quot;lastname&quot;] = &quot;Smith&quot;; myArray[&quot;age&quot;] = 25;  Now if I wanted to remove &quot;lastname&quot;?....is there some equivalent of myArray[&quot;lastname&quot;].remove()? (I need the element gone because the number of elements is important and I want to keep things clean.)
4854
I've just had to write a string reverse function in C# 2.0 (i.e. LINQ not available) and came up with this:  public string Reverse(string text) {     char[] cArray = text.ToCharArray();     string reverse = String.Empty;     for (int i = cArray.Length - 1; i &gt; -1; i--)     {         reverse += cArray[i];     }     return reverse; }   Personally I'm not crazy about the function and am convinced that there's a better way to do it. Is there?
80880
My code:  a = '2.3'   I wanted to display a as a floating point value.  Since a is a string, I tried:  float(a)   The result I got was :  2.2999999999999998   I want a solution for this problem. Please, kindly help me.  I was following .
1314
I have a char in c#:  char foo = '2';   Now I want to get the 2 into an int.  I find that Convert.ToInt32 returns the actual decimal value of the char and not the number 2.  The following will work:  int bar = Convert.ToInt32(new string(foo, 1));   int.parse only works on strings as well.    Is there no native function in C# to go from a char to int without making it a string?  I know this is trivial but it just seems odd that there's nothing native to directly make the conversion.
14414
I am trying to convert an integer number in C into an array containing each of that number's digits  i.e.  if I have   int number = 5400   how can I get to   int numberArray[4]   where   numberArray[0] = 0; numberArray[1] = 0; numberArray[2] = 4; numberArray[3] = 5;   Any suggestions gratefully received.
8128
What is the best possible way to check if a string can be represented as a number in Python?   The function I currently have right now is:  def is_number(s):     try:         float(s)         return True     except ValueError:         return False   Which, not only is ugly and slow, seems clunky. However I haven't found a better method because calling float in the main function is even worse.