Sunday 15 September 2013

javascript - pushing to array element appended with single quote -



javascript - pushing to array element appended with single quote -

the next varibale evaluated , adding array element, getting single quote when array printed, how avoid this,here code

var t1 = "date.utc("+vardate[0]+','+vardate[1]+','+vardate[2]+")" console.log(t1)

the output

date.utc(2001,1,23)

then added t1 array

diffarray.push(t1) console.log(t1)

it appended single quote why ? how avoid ?

[ 'date.utc(2001,1,23)']

this console.log() showing item in array string. t1 variable has been string there no difference in internal representation, how console.log() chooses display it.

if console.log(diffarray[0]), see original representation without quotes because that's console.log() when give plain string. when give console.log() array, puts quotes around elements strings indicate difference between string , other type array might hold.

look in console jsfiddle: http://jsfiddle.net/jfriend00/yrannpm2/

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)"]

javascript arrays node.js

No comments:

Post a Comment