javascript - pushing to array element appended with single quote -


The following verb is evaluated and adding to the array element, getting a single quotation when the array is printed, how to To save, here is the code

  var t1 = "Date.UTC (" + varDate [0] + ',' + varDate [1] + ',' + varDate [2] + " ) "Console .log (t1)  

is output

  date.utc (20011,23)  
< P> Added t1 for an array

  diffArray.push (t1) console.log (t1)  

Why was this single quote added? How to avoid it?

  ['Date.UTC (2001,1,23)']  

This is just showing you that the item string in the array is your t1 variable has always been a string, so internal representation There is no difference, just how console.log () chooses to display it.

If you do console.log (diffArray [0]) , you will see the original presentation without quotation marks, because it is the same as console.log () When you give it a plain string when you give a console.log () array, it gives the quotation around any element, the difference between the string Indicates and can catch any other type of array.

Look for this JSFDial in your console:

  console.log (t1); // date.utc (2001,1,23) console.log (diffArray [0]); // date.utc (2001,1,23) console.log (diffArray); // ["Date.Utc (2001,1,23)"]  

Comments