So I am trying to convert an array of strings to an array of numbers using the following code.    let a = ["0", "0"]; let b = Array.from(a, parseInt); console.log(b);     and what I get is  b = [0, NaN];   I am familiar with a similar issue using Array.map() since it provides three arguments to parseInt() and the second argument (index) is interpreted as a radix by parseInt(). But it shouldn't be the case for Array.from().  Can someone give me an explanation please?
1890
From the :  [1,4,9].map(Math.sqrt)   will yield:  [1,2,3]   Why then does this:  ['1','2','3'].map(parseInt)   yield this:  [1, NaN, NaN]   I have tested in Firefox 3.0.1 and Chrome 0.3 and just as a disclaimer, I know this is not cross-browser functionality (no IE).  I found out that the following will accomplish the desired effect. However, it still doesn’t explain the errant behavior of parseInt.  ['1','2','3'].map(function(i){return +i;}) // returns [1,2,3]
26027
How do I append an object (such as a string or number) to an array in JavaScript?
61612
I'm looking for a  way to convert numbers to string format, dropping any redundant '.0'   The input data is a mix of floats and strings. Desired output:  0   --> '0'  0.0 --> '0'  0.1 --> '0.1'  1.0 --> '1'  I've come up with the following generator expression, but I wonder if there's a faster way:  (str(i).rstrip('.0') if i else '0' for i in lst)   The truth check is there to prevent 0 from becoming an empty string.  EDIT: The more or less acceptable solution I have for now is this:  ('%d'%i if i == int(i) else '%s'%i for i in lst)   It just seems strange that there is no elegant way to handle this (fairly straightforward) case in python.
5995
When displaying the value of a decimal currently with .ToString(), it's accurate to like 15 decimal places, and since I'm using it to represent dollars and cents, I only want the output to be 2 decimal places.   Do I use a variation of .ToString() for this?
5148
I have recently been thinking about the difference between the two ways of defining an array:   int[] array int array[]   Is there a difference?
7083
I need to  an object to . I'm using . Is there a "standard" way to do this?  My specific situation: I have an array defined as shown below:  var countries = new Array(); countries[0] = 'ga'; countries[1] = 'cd'; ...   and I need to turn this into a string to pass to  like this:  $.ajax({     type: "POST",     url: "Concessions.aspx/GetConcessions",     data: "{'countries':['ga','cd']}", ...
80089
I have seen a solution that I don't get to work - I need to change data type from string to integer and I did what is shown i the image below Can someone point out what I do wrong?
70173
While working on a project, I came across a JS-script created by a former employee that basically creates a report in the form of  Name : Value Name2 : Value2   etc.  The peoblem is that the values can sometimes be floats (with different precision), integers, or even in the form 2.20011E+17. What I want to output are pure integers. I don't know a lot of JavaScript, though.  How would I go about writing a method that takes these sometimes-floats and makes them integers?
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 = ???;
330
The primitive types (number, string, etc.) are passed by value, but objects are unknown, because they can be both passed-by-value (in case we consider that a variable holding an object is in fact a reference to the object) and passed-by-reference (when we consider that the variable to the object holds the object itself).  Although it doesn't really matter at the end, I want to know what is the correct way to present the arguments passing conventions. Is there an excerpt from JavaScript specification, which defines what should be the semantics regarding this?
4129
I have this string  'john smith~123 Street~Apt 4~New York~NY~12345'   Using JavaScript, what is the fastest way to parse this into  var name = "john smith"; var street= "123 Street"; //etc...
7953
Can a string be used as array index in C?  Ex: String      Corresponding value "ONE"       1 "TWO"       2 "FIVE"      5 "TEN"       10  When a string in the above list is passed to the function, the function must return the corresponding value indicated above. Can this be achieved by declaring a constant array with string as index  int *x; x["ONE"]  = 1; x["TWO"]  = 2; x["FIVE"] = 5; x["TEN"]  = 5;  return x["string received by the function"];   The above logic does not work as expected; is there a workaround to implement the above logic in order to have a string-indexed array?
23702
Just curious:    4 instanceof Number => false new Number(4) instanceof Number => true?   Why is this? Same with strings:    'some string' instanceof String returns false new String('some string') instanceof String => true String('some string') instanceof String also returns false ('some string').toString instanceof String also returns false   For object, array or function types the instanceof operator works as expected. I just don't know how to understand this.  [new insights]  Object.prototype.is = function() {         var test = arguments.length ? [].slice.call(arguments) : null            ,self = this.constructor;         return test ? !!(test.filter(function(a){return a === self}).length)                : (this.constructor.name ||                   (String(self).match ( /^function\s*([^\s(]+)/im )                     || [0,'ANONYMOUS_CONSTRUCTOR']) [1] ); } // usage var Newclass = function(){};  // anonymous Constructor function var Some = function Some(){}; // named Constructor function (5).is();                     //=&gt; Number 'hello world'.is();           //=&gt; String (new Newclass()).is();        //=&gt; ANONYMOUS_CONSTRUCTOR (new Some()).is();            //=&gt; Some /[a-z]/.is();                 //=&gt; RegExp '5'.is(Number);               //=&gt; false '5'.is(String);               //=&gt; true
872
In Java, arrays don't override toString(), so if you try to print one directly, you get the className + '@' + the hex of the  of the array, as defined by Object.toString():  int[] intArray = new int[] {1, 2, 3, 4, 5}; System.out.println(intArray);     // prints something like '[I@3343c8b3'   But usually, we'd actually want something more like [1, 2, 3, 4, 5]. What's the simplest way of doing that? Here are some example inputs and outputs:  // Array of primitives: int[] intArray = new int[] {1, 2, 3, 4, 5}; //output: [1, 2, 3, 4, 5]  // Array of object references: String[] strArray = new String[] {"John", "Mary", "Bob"}; //output: [John, Mary, Bob]
13470
I am a little surprised by the following.  Example 1:  char s[100] = "abcd"; // declare and initialize - WORKS   Example 2:  char s[100]; // declare s = "hello"; // initalize - DOESN'T WORK ('lvalue required' error)   I'm wondering why the second approach doesn't work. It seems natural that it should (it works with other data types)? Could someone explain me the logic behind this?
60150
I'm working with some example java code for making md5 hashes. One part converts the results from bytes to a string of hex digits:  byte messageDigest[] = algorithm.digest();      StringBuffer hexString = new StringBuffer(); for (int i=0;i&lt;messageDigest.length;i++) {     hexString.append(Integer.toHexString(0xFF &amp; messageDigest[i]));     }   However, it doesn't quite work since toHexString apparently drops off leading zeros. So, what's the simplest way to go from byte array to hex string that maintains the leading zeros?
6261
I am looking for a JavaScript array insert method, in the style of:  arr.insert(index, item)   Preferably in jQuery, but any JavaScript implementation will do at this point.